【发布时间】:2012-12-31 02:18:54
【问题描述】:
如何启动 Intent 以打开默认导航应用程序(例如 Google Navigation 或 Google Maps)或让用户有机会在导航应用程序中进行选择。
提前致谢。
【问题讨论】:
标签: android
如何启动 Intent 以打开默认导航应用程序(例如 Google Navigation 或 Google Maps)或让用户有机会在导航应用程序中进行选择。
提前致谢。
【问题讨论】:
标签: android
试试:
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,以便用户可以在某些应用程序之间进行选择。
【讨论】:
您必须使用带有 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。
【讨论】: