通过在Android意图启动谷歌地图路线 [英] Launching Google Maps Directions via an intent on Android

查看:369
本文介绍了通过在Android意图启动谷歌地图路线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序需要显示来自谷歌地图的方向到B,但我不想把谷歌地图在我的应用程序 - 相反,我想用一个Intent来启动它。这可能吗?如果是的话,怎么办?

My app needs to show Google Maps directions from A to B, but I don't want to put the Google Maps into my application - instead, I want to launch it using an Intent. Is this possible? If yes, how?

推荐答案

您可以使用这样的:

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);

要开始从当前位置导航,删除 SADDR 参数和值。

To start the navigation from the current location, remove the saddr parameter and value.

您可以用它代替纬度和经度的实际街道地址。然而,这将带给用户一个对话框,通过浏览器或谷歌地图打开它之间做出选择。

You can use an actual street address instead of latitude and longitude. However this will give the user a dialog to choose between opening it via browser or Google Maps.

如果你在美国,你可以使用一个非官方的方式(因为它是不是官方的,我不建议使用它)。这将会启动谷歌地图导航模式。用它,因为我住的地方它不可没玩过。

If you are in the US, you could use an unofficial way (Since it isn't official, I don't recommend using it). This will fire up Google Maps in navigation mode. Haven't played with it since where I live it isn't available.

Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
    Uri.parse("google.navigation:q=an+address+city"));

这篇关于通过在Android意图启动谷歌地图路线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆