我想将Yandex 地图添加到我的 android 应用程序中。
这个问题似乎有点长,但那是因为我分享了我所有的代码。提前感谢您的耐心等待。
与谷歌地图相比,我自然找不到太多来源。
我使用了这个源首先我想运行一个简单的示例。所以我使用了这个样本。 最后我取得了一些成就。我没有收到任何错误。但我也无法显示地图。我只有一些方形区域(已选中,已选中)和一个“目标图标”。您可以在下面看到活动类代码。
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:2.4.2@aar'
并将此块添加到外部 build.gradle 文件中:
allprojects {
repositories {
jcenter()
maven { url 'https://github.com/yandexmobile/yandexmapkit-android/raw/maven/' }
}
}
以下屏幕截图是 genymotion 的输出。我错过了什么,为什么不能显示地图。实际上,我上面给出的来源是俄语,所以我尽我所能,但尽管我可能错过了一些东西。任何的想法?如果存在其他来源或文档(英文),您可能会向我建议如何将 yandex 地图添加到 android 应用程序中,我很乐意看到。提前致谢。