0

我使用 yandex mapkit 尝试获得准确的 latlng,但它绘制准确但没有让听众失败我使用链接https://github.com/yandexmobile/yandexmapkit-android/blob/master/yandexmapkit-sample/src/ru/mapkittest/ geocode/OverlayGeoCode.java但未调用监听器 如何在每个点移动时获取监听器

谢谢, 沙比尔穆罕默德

4

1 回答 1

2

如果您想在点击地图上的某个点后对其进行地理编码,则需要执行以下操作。

  1. 扩展 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;
        }
    }
    
  2. 使用示例

    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()));
    
        }
    }
    
  3. 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>
    
于 2016-02-18T13:07:52.990 回答