2016-04-15 89 views
0

我想添加一個Yandex圖到我的Android應用程序。添加Yandex圖在Android應用程序

問題可以看起來有點長,但就是因爲我分享我的所有代碼。感謝您的耐心提前。

我找不到太多源比較谷歌地圖自然。

I used this source首先,我想運行一個簡單的示例。 So I used this sample. 最後我實現了一些東西。我沒有得到任何錯誤。但我也無法顯示地圖。我只是有一些squarred區域(格仔,檢查)和一個「目標圖標」。您可以在下面看到活動課程代碼。

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); 
     } 
    }); 


} 

} 

以下是我的佈局文件。

<?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> 

我也在的build.gradle文件加入這一行下的依賴關係:

compile 'ru.yandex:yandexmapkit:[email protected]' 

而且還增加了該塊進入外的build.gradle文件:

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

    } 
} 

以下截圖是輸出來自genymotion。我錯過了什麼,爲什麼不能顯示地圖。其實我上面給出的來源是俄語,所以我盡力做到盡我所能,但儘管我可能錯過了一些東西。 有什麼想法?如果存在另一個信號源或文檔(英文),你可以建議我談如何添加Yandex圖到Android應用,我很想看到。提前致謝。

enter image description here

+0

您是否試過在真實設備上運行應用程序? –

+0

@NikolaiDoronin尚未嘗試。可能需要一些時間。我會讓你知道的。順便說一句,當我刪除佈局文件中的api鍵時,它再次以相同的方式工作。所以我想也許鑰匙沒有激活,或者我不知道這是什麼意思? – Hilal

+0

@NikolaiDoronin我在真實的設備上再次嘗試了同樣的結果,沒有地圖只有正方形。 – Hilal

回答

0

終於解決了這個問題。我發送了一封電子郵件給yandex支持,他們給我發了api密鑰,他們說唯一獲得api密鑰的方法是與他們聯繫。

This is yandex support page.

只需填寫一個mapkit API密鑰的形式和要求。他們在兩天內返回。

感謝您的幫助

相關問題