How can I return the location pressed to the MapActivity from an Overlay onTap method
I have an activity that has a button which opens a new MapActivity to select a location by tapping on the map.
The map has an overlay that overrides the onTap method to 开发者_高级运维get the location but I want to return that location to the previous activity but, I don't know how to return the geopoint to the mapactivity in order to call the setResult() and finish() methods, because I can't call them from the Overlay.onTap method.
Any ideas?
Solved this way:
class tapOverlay extends Overlay
{
public GeoPoint lastTap=null;
String strCalle;
private Context context;
public tapOverlay(Context c)
{
this.context=c;
}
}
@Override
public boolean onTap(GeoPoint p, MapView mapView) {
lastTap = p;
mapView.getController().animateTo(p);
...
strCalle = sb.toString(); //from geocoder
...
devolverResultado();
return true;
}
private void devolverResultado()
{
MapActivity ma = (MapActivity) context;
Intent i = new Intent();
Bundle b = new Bundle();
b.putInt("dlat", lastTap.getLatitudeE6());
b.putInt("dlng", lastTap.getLongitudeE6());
b.putString("calle",strCalle);
i.putExtras(b);
ma.setResult(Activity.RESULT_OK, i);
ma.finish();
}
Call the new activity using an intent ...
Then , Use onActivityResult( int , int , Intent) to call the new activity from the current activity..... U should get back the data from the new activity when u finish the called activity as the calling activity is placed on the stack ...
Hope this helps ... :)
精彩评论