Issue
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?
Solution
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();
}
Answered By - Fernando Gallego
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.