我使用yandex mapkit尝试获得准确的latlng但是它准确地绘制但是没有得到监听器失败我使用链接https://github.com/yandexmobile/yandexmapkit-android/blob/master/yandexmapkit-sample/src/ru/mapkittest/geocode/OverlayGeoCode.java但是监听器没有调用如何在每个点移动时获得监听器
谢谢, Shabeer Mohamed
答案 0 :(得分:2)
如果您想在点击地图后对地图进行地理编码,则需要执行以下操作。
扩展Overlay类并实现GeoCodeListener
public class GeoCodeOverlay extends Overlay implements GeoCodeListener {
public GeoCodeOverlay(MapController mapController) {
super(mapController);
}
@Override
public boolean onFinishGeoCode(final GeoCode geoCode) {
if (geoCode != null) {
getMapController().getMapView().post(new Runnable() {
@Override
public void run() {
// show display name of the point
Toast.makeText(getMapController().getContext(),
geoCode.getDisplayName(), Toast.LENGTH_LONG).show();
}
});
}
return true;
}
@Override
public boolean onSingleTapUp(float x, float y) {
getMapController().getDownloader()
.getGeoCode(this, getMapController().getGeoPoint(new ScreenPoint(x, y)));
return true;
}
}
使用示例
public class GeoCoderActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_geo_coder);
final MapView mapView = (MapView) findViewById(R.id.map);
mapView.getMapController().getOverlayManager()
.getMyLocation().setEnabled(true);
mapView.getMapController().getOverlayManager()
.addOverlay(new GeoCodeOverlay(mapView.getMapController()));
}
}
activity_geo_coder.xml
。不要忘记添加API密钥
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
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"
tools:context="com.mapkittest.GeoCoderActivity">
<ru.yandex.yandexmapkit.MapView
android:id="@+id/map"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:apiKey="PLACE_YOUR_API_HERE"
/>
</RelativeLayout>