0

i used yandex mapkit try to get accurate latlng but it ploted accurately but not get listener failed i used the link https://github.com/yandexmobile/yandexmapkit-android/blob/master/yandexmapkit-sample/src/ru/mapkittest/geocode/OverlayGeoCode.java but listener not called how to get listener when each and every point move

Thanks, Shabeer Mohamed

sabeer
  • 603
  • 10
  • 28

1 Answers1

2

If you want to geocode a point on a map after you tap on it, you need to do the following.

  1. Extend Overlay class and implement 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. Example of usage

    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. Don't forget to add your API key

    <?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>
    
Vlad
  • 110
  • 1
  • 5