Android 地图后退按钮
我正在开发一个应用程序,该应用程序在地图上显示由 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
取决于您使用的 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.
这是因为您正在开始活动并加载空白地图
,然后创建一个 Intent 以使用 kml 文件启动NEW 地图。
所以当您回击时会发生什么,它会留下第二张地图(带有kml 文件)并返回到第一个地图(空白)。
It's because you're starting your activity and loading a blank map
and then creating an Intent to launch a NEW map with the kml file
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).