androidgoogle-mapsyandexyandex-mapsyandex-api

Add Yandex Map in android application


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


Solution

  • 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