如何从 Overlay onTap 方法将按下的位置返回到 MapActivity

发布于 2024-09-16 05:25:54 字数 196 浏览 3 评论 0原文

我有一个活动,有一个按钮,可以打开一个新的 MapActivity,通过点击地图来选择位置。

地图有一个覆盖层,它覆盖 onTap 方法来获取位置,但我想将该位置返回到上一个活动,但是,我不知道如何将地理点返回到地图活动以便调用 setResult() 并完成() 方法,因为我无法从 Overlay.onTap 方法中调用它们。

有什么想法吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

魔法少女 2024-09-23 05:25:54

是这样解决的:

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

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();
}
初心未许 2024-09-23 05:25:54

使用意图调用新活动...

然后,使用 onActivityResult( int , int , Intent) 从当前活动调用新活动.....
当您完成被调用的活动时,您应该从新活动取回数据,因为调用活动被放置在堆栈上...

希望这有帮助...:)

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文