Android 地图后退按钮

发布于 2024-09-05 22:41:41 字数 670 浏览 7 评论 0原文

我正在开发一个应用程序,该应用程序在地图上显示由 KML 文件确定的路径。具体来说,在启动地图的 MapActivity 中:

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    MapView mapView = (MapView) findViewById(R.id.mapview);
    mapView.setBuiltInZoomControls(true);

    Uri uri = Uri.parse("geo:0,0?q=http://urltokml");
    Intent mapIntent = new Intent(Intent.ACTION_VIEW, uri);
    mapIntent.setData(uri);

    startActivity(Intent.createChooser(mapIntent, kmlFile));
    finish();
}

地图加载正常,几秒钟后,KML 描述的路径就会显示出来。问题是,当我按“后退”按钮时,它不会返回到上一个屏幕,而只是隐藏 KML 叠加层。如果再次按下“返回”按钮,将返回到上一屏幕。

关于如何解决这个问题有什么想法吗?

I'm developing an application that shows a path on a map, determined by a KML file. Specifically, in the MapActivity that is starting the map:

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    MapView mapView = (MapView) findViewById(R.id.mapview);
    mapView.setBuiltInZoomControls(true);

    Uri uri = Uri.parse("geo:0,0?q=http://urltokml");
    Intent mapIntent = new Intent(Intent.ACTION_VIEW, uri);
    mapIntent.setData(uri);

    startActivity(Intent.createChooser(mapIntent, kmlFile));
    finish();
}

The map loads fine and after a few seconds the path described by the KML shows up. The problem is, when I press the "Back" button, it does not return to the previous screen but instead just hides the KML overlay. If the "Back" button is pressed again, it will return to the previous screen.

Any ideas of how to solve this?

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

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

发布评论

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

评论(2

年华零落成诗 2024-09-12 22:41:41

取决于您使用的 API 版本...在更高版本中,有一个“OnBackPressed”方法,您可以在 Activity 中重写该方法来调整后退行为。

Depends on what version of the API you are using... in the later versions there is an "OnBackPressed" method that you can override in your activity to adjust the back behavior.

浅浅淡淡 2024-09-12 22:41:41

这是因为您正在开始活动并加载空白地图

public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    MapView mapView = (MapView) findViewById(R.id.mapview);
    mapView.setBuiltInZoomControls(true);

,然后创建一个 Intent 以使用 kml 文件启动NEW 地图。

    Uri uri = Uri.parse("geo:0,0?q=http://urltokml");
    Intent mapIntent = new Intent(Intent.ACTION_VIEW, uri);
    mapIntent.setData(uri);

    startActivity(Intent.createChooser(mapIntent, kmlFile));
    finish();
}

所以当您回击时会发生什么,它会留下第二张地图(带有kml 文件)并返回到第一个地图(空白)。

It's because you're starting your activity and loading a blank map

public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    MapView mapView = (MapView) findViewById(R.id.mapview);
    mapView.setBuiltInZoomControls(true);

and then creating an Intent to launch a NEW map with the kml file

    Uri uri = Uri.parse("geo:0,0?q=http://urltokml");
    Intent mapIntent = new Intent(Intent.ACTION_VIEW, uri);
    mapIntent.setData(uri);

    startActivity(Intent.createChooser(mapIntent, kmlFile));
    finish();
}

So what's happening when you hit back is that it's leaving the second map (with the kml file) and returning to the first map (that is blank).

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