如何直接从我的应用程序使用 Google 地图导航

Posted

技术标签:

【中文标题】如何直接从我的应用程序使用 Google 地图导航【英文标题】:How to Navigate with Google Maps directly from my application 【发布时间】:2014-06-13 10:19:05 【问题描述】:

早安,

我正在尝试使用 Google 地图将我的应用用户导航到某个地址/位置。根据我目前在网上找到的内容,我尝试了以下方法:

    Intent intent = new Intent(android.content.Intent.ACTION_VIEW, 
                        Uri.parse("http://maps.google.com/maps?saddr=-36.181,27.949&daddr=-36.174732,27.949770"));
                    startActivity(intent);

现在这一切都很好,它打开了谷歌地图,但在我真正进入导航之前它问了我很多事情。

1:它首先让我选择行程 2:然后它会告诉我行程 3:然后我必须单击小箭头(导航按钮)

然后它才开始导航。

我有没有办法在我的意图中指定使用第一条路线并开始立即/自动导航?

第二点,一旦我到达目的地或者我想返回/取消,返回按钮需要带我回到我的应用程序,现在它会返回显示路线,然后我点击再次返回,它说您确定要退出导航。

或者我可以在您到达目的地后收听地图发布的 Intent。那么当用户到达目的地时,我的应用程序将再次成为焦点?

【问题讨论】:

【参考方案1】:

试试这个方法

String urlAddress = "http://maps.google.com/maps?q="+ lat + ","+ lng + "("
                + your_location_name + ")&iwloc=A&hl=es";
        Intent intent = new Intent(Intent.ACTION_VIEW,
                Uri.parse(urlAddress));
        startActivity(intent);

这将在给定的有效 lat、lng 值上打开谷歌地图,并将 your_location_name 显示为地名。

【讨论】:

您能否澄清一下,your_location_name 是目标地址吗?以及你当前位置的日志和纬度? 这将在给定的有效 lat、lng 值上打开谷歌地图,并将 your_location_name 显示为地名。 但这不会自动开始导航? @Zapnologica 对不起,我错过了理解。请看看这个***.com/questions/2662531/…【参考方案2】:
// try this way,hope this will help you to solve your problem.

String uri = "http://maps.google.com/maps?f=d&hl=es&saddr=-36.181,27.949&daddr=-36.174732,27.949770";
Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(uri));
intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");
startActivity(intent);

【讨论】:

产生的结果与我最初的结果相同。 当您尝试通过默认的谷歌地图应用程序显示路线时,我们不会按照他的步骤进行操作,如果您不想要这样的步骤,那么您必须开发您的自定义根实现代码。跨度> 【参考方案3】:
String uri = "google.navigation:q=%f, %f";
Intent navIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(String                  .format(Locale.US, uri, customerDropOffLatLng.latitude, customerDropOffLatLng.longitude)));
navIntent.setPackage("com.google.android.apps.maps");
startActivity(navIntent);

【讨论】:

欢迎来到 SO。请不要只回答代码;提供一些上下文/解释。见***.com/help/how-to-answer

以上是关于如何直接从我的应用程序使用 Google 地图导航的主要内容,如果未能解决你的问题,请参考以下文章

如何使用实时导航在Kotlin的Google地图上绘制最短路径?

打开 Apple 地图以设置目的地名称进行导航

如何从我的 phonegap 应用程序打开 TomTom 导航应用程序?

iOS : 如何在谷歌地图上启用音频方向

带有多个目标的苹果或谷歌地图的 ios 导航

如何从我的应用程序中打开标准的 Google Map 应用程序?