【问题标题】:Open default navigation app using an address使用地址打开默认导航应用
【发布时间】:2012-12-31 02:18:54
【问题描述】:

如何启动 Intent 以打开默认导航应用程序(例如 Google Navigation 或 Google Maps)或让用户有机会在导航应用程序中进行选择。

提前致谢。

【问题讨论】:

    标签: android


    【解决方案1】:

    试试:

    Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("google.navigation:q=New+York+NY")); startActivity(i);
    

    或者使用这个,这样标准导航应用就会启动:

    Intent intent = new Intent(android.content.Intent.ACTION_VIEW, 
    Uri.parse("http://maps.google.com/maps?saddr=20.344,34.34&daddr=20.5666,45.345"));
    startActivity(intent);
    

    如果不想弹出对话框,请在 startActivity 之前添加此行:

    intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");
    

    另请参阅:How to check programmatically if an application is installed or not in Android?Android: detect when app is installed,您可以制作自己的 Window,以便用户可以在某些应用程序之间进行选择。

    【讨论】:

    • 我尝试了您的两个建议,但第一个只是打开 Google 导航,另一个只打开了选择的可能性:(我的两个浏览器或 Google 地图,而不是例如 Google 导航)
    • 我希望它能够同时选择谷歌地图和谷歌导航或用户可能安装的任何应用程序来导航或获取路线。但我什至不知道这是否可能。
    【解决方案2】:

    您必须使用带有 ACTION_VIEW 和 geo 数据方案的 Intent。

    使用geo:latitude,longitude 的问题是谷歌地图只以你的点为中心,没有任何大头针或标签。

    这很令人困惑,尤其是当您需要指向一个精确的位置或/并询问方向时。

    如果您使用查询参数geo:lat,lon?q=name 来标记您的地理点,它会使用查询进行搜索并忽略纬度和经度参数。

    我找到了一种将地图以经纬度居中并显示带有自定义标签的图钉的方法,在询问方向或任何其他操作时显示非常好并且很有用:

    Intent intent = new Intent(android.content.Intent.ACTION_VIEW, 
    Uri.parse("geo:0,0?q=37.423156,-122.084917 (" + name + ")");
    startActivity(intent);
    

    此意图来自官方“G 应用”意图列表here

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-03-31
      • 1970-01-01
      • 1970-01-01
      • 2015-07-29
      • 2020-01-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多