Если вы хотите геокодировать точку на карте после нажатия на нее, вам нужно сделать следующее.
Расширение класса 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>