2016-04-15 91 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密钥的形式和要求。他们在两天内返回。

感谢您的帮助

相关问题