views:

78

answers:

2

Hi,

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?

A: 

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 ... :)

ravi
Well I solved it but not that way. I passed the context to the overlay constructor and then, on the onTap method, I casted it back to a MapView object to be able to call the setResult method, and it worked
ferdy182
A: 

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();
}
ferdy182