【问题标题】:Android Maps Back ButtonAndroid 地图返回按钮
【发布时间】:2010-06-16 19:52:24
【问题描述】:

我正在开发一个在地图上显示由 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 叠加层。如果再次按下“返回”按钮,将返回上一屏幕。

关于如何解决这个问题的任何想法?

【问题讨论】:

    标签: java android google-maps kml


    【解决方案1】:

    取决于您使用的 API 版本...在更高版本中,您可以在 Activity 中覆盖“OnBackPressed”方法以调整后退行为。

    【讨论】:

      【解决方案2】:

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

      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 文件)并返回到第一张地图(即空白)。

      【讨论】:

      • 我现在正在调用 Uri uri = Uri.parse("geo:0,0?q=urlhere"); Intent mapIntent = new Intent(Intent.ACTION_VIEW, uri); mapIntent.setData (uri); startActivity(Intent.createChooser(mapIntent, "Title")); 来自另一个活动(非映射活动),但后退按钮具有相同的效果。
      • 当时是内置的Maps程序,我不知道它是如何处理请求的。
      猜你喜欢
      • 2014-09-27
      • 2023-03-28
      • 1970-01-01
      • 1970-01-01
      • 2014-04-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多