2

I want to add a Yandex Map into my android application.

The question can be seem a little long but that is because of I shared all my codes. Thanks for your patience in advance.

I couldn't find much source compare to Google Maps naturally.

I used this source First I wanted to run a simple sample. So I used this sample. Finally I achieved something. I don't get any error. But I also couldn't display the map. I only have some squarred area (chequered, checked) and one "target icon". You can see the activity class code below.

import android.app.Activity;
import android.os.Bundle;
import android.widget.LinearLayout;
import android.widget.TextView;
//import ru.mapkittest.R;
import ru.yandex.yandexmapkit.*;
import ru.yandex.yandexmapkit.overlay.location.MyLocationItem;
import ru.yandex.yandexmapkit.overlay.location.OnMyLocationListener;

/**
 * MapLayers.java
 *
 * This file is a part of the Yandex Map Kit.
 *
 * Version for Android © 2012 YANDEX
 *
 * You may not use this file except in compliance with the License.
 * You may obtain a copy of the License at http://legal.yandex.ru/mapkit/
 *
 */

public class MapMyLocationChangeActivity extends Activity implements     OnMyLocationListener{
/** Called when the activity is first created. */
MapController mMapController;
LinearLayout mView;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setTitle("Title");

    setContentView(R.layout.activity_main);

    final MapView mapView = (MapView) findViewById(R.id.map);
    mapView.showBuiltInScreenButtons(true);

    mMapController = mapView.getMapController();
    // add listener
        mMapController.getOverlayManager().getMyLocation().addMyLocationListener(this);

    mView = (LinearLayout) findViewById(R.id.view);

}

@Override
public void onMyLocationChange(MyLocationItem myLocationItem) {
    // TODO Auto-generated method stub
    final TextView textView = new TextView(this);
    textView.setText("Type " + myLocationItem.getType()+" GeoPoint ["+myLocationItem.getGeoPoint().getLat()+","+myLocationItem.getGeoPoint().getLon()+"]");
    runOnUiThread(new Runnable() {
        @Override
        public void run() {
            // TODO Auto-generated method stub
            mView.addView(textView);
        }
    });


}

}

The following is my layout file.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context="gcm.b4deploy.com.yandexmap.MainActivity"
    tools:showIn="@layout/activity_main"
    android:orientation="vertical"
>


<ru.yandex.yandexmapkit.MapView
    android:id="@+id/map"
    android:layout_width="fill_parent"
    android:layout_height="300dip"
    android:apiKey="myapikey" />

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >

    <LinearLayout
        android:id="@+id/view"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >
    </LinearLayout>
</ScrollView>


</LinearLayout>

I also added this line under dependencies in build.gradle file:

compile 'ru.yandex:yandexmapkit:2.4.2@aar'

And also added this block into outer build.gradle file:

allprojects {
    repositories {
        jcenter()
        maven { url 'https://github.com/yandexmobile/yandexmapkit-android/raw/maven/' }

    }
 }

Following screenshot is output from genymotion. What am I missing, why can't display the map. Actually the source that I gave above is in Russian so I tried to do as best I can but although I may missed something. Any idea? If there exist another source or documentation (in english ) that you may suggest to me about how to add yandex map into android app, I would love to see that. Thanks in advance.

enter image description here

Hilal
  • 902
  • 2
  • 22
  • 47
  • Have you tried to run your application on a real device? – Mikalai Daronin Apr 15 '16 at 11:56
  • @NikolaiDoronin Not yet, trying now. May take a time. I will let you know. BTW when I deleted the api key in layout file, it again worked as the same way. So I thought maybe the key is not activated or I dont know what does it mean? – Hilal Apr 15 '16 at 12:33
  • @NikolaiDoronin I tried on real device again got same result, there is no map only there are squares. – Hilal Apr 15 '16 at 13:30
  • The problem might be with you API key. Also, could you check if [Yandex Maps app](https://play.google.com/store/apps/details?id=ru.yandex.yandexmaps&hl=en) is working on your devices? – Mikalai Daronin Apr 15 '16 at 13:33
  • @NikolaiDoronin in emulator Yandex Maps app is working. And in emulator I could display google maps inside my application without any problem. I got api key from this link. [link](https://tech.yandex.com/keys/get/?service=trnsl) I registered and got api key and pasted it into layout file as it is in samples from github link -> [link](https://github.com/yandexmobile/yandexmapkit-android/blob/master/yandexmapkit-sample/res/layout/sample8.xml) I dont know whats wrong – Hilal Apr 15 '16 at 13:43
  • Hmm, I'm not sure that your link is correct way to obtain an access token. Please have a look at [this issue](https://github.com/yandexmobile/yandexmapkit-android/issues/198). – Mikalai Daronin Apr 15 '16 at 13:55
  • @NikolaiDoronin Surprisingly new api key is not needed. I wrote 1234567890 as it is in github sample it worked :) Thank you so much you were the only helper =) – Hilal Apr 15 '16 at 13:57

2 Answers2

0

Finally solved the problem. I sent an email to yandex support and they sent me api key and they said that the only way to get an api key is contacting with them.

This is yandex support page.

Just fill the form and request for a mapkit api key. They return in two days.

Thanks for all help

Hilal
  • 902
  • 2
  • 22
  • 47
0

I had the same problem first then I managed it with adding

@Override public void onStart() { super.onStart(); mapView.onStart(); MapKitFactory.getInstance().onStart(); }

and

@Override public void onStop() { super.onStop(); mapView.onStop(); MapKitFactory.getInstance().onStop(); } as mantioned here

Zohidjon Akbarov
  • 3,223
  • 1
  • 9
  • 9