I have MapActivity with working mapview in my application. The problem that I faced is that I want to tap any location on the map, show the dialog with text example:
do you want to mark this location?
If yes, it’ll extract the coordinates and save it somewhere (that doesn’t matter where right now),
how can I do that? I’ve tried to use dispatchTouchEvent method but I failed.
@Override
public boolean dispatchTouchEvent(MotionEvent event)
{
if (event.getAction() == 1) {
GeoPoint p = mapView.getProjection().fromPixels(
(int) event.getX(),
(int) event.getY());
// send the intent from here to your next activity with the GeoPoint coords.
Toast.makeText(getBaseContext(),
p.getLatitudeE6() / 1E6 + "," +
p.getLongitudeE6() /1E6 ,
Toast.LENGTH_SHORT).show();
}
return false;
}
It shows me my coordinates – but it’s doing it everytime when I just touch the map – I can’t even move it.
The javadoc for
dispatchTouchEvent(MotionEvent event)states the following:So you should handle all other events with the original method: