Android 导航意图 [英] Android Navigation intent

查看:16
本文介绍了Android 导航意图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果您将 Google 地图方向发送到您的 Android 手机,则可以在地图应用程序中打开它,这看起来非常合乎逻辑,其背后的代码也是如此.

If you mail a Google Maps direction to your Android phone, you have the possibility to open it in the Maps appliaction, this seems perfectly logical, as does the code behind it.

现在,一旦进入地图应用程序,您就可以在导航应用程序中打开这些方向以及这些确切的方向.

Now, once in the Maps App, you have the possibility to open these directions in the Navigation App, with those exact directions.

这是如何工作的?做起来一定没那么难,我知道的意图

How does this work? It must not be that difficult to do it, I know about the intent with

"google.navigation:q=..."

但这仅适用于某些设备,并且仅适用于坐标或地址...没有地图方向?

But this only works on some devices and only with coördinates or addresses... No Maps directions?

谁能帮我解决这个问题?

Can anyone help me out with this?

这就是 URL 的样子:

This is what the URL looks like:

https://maps.google.com/maps?saddr=Durbanville,+Cape+Town,+Western+Cape,+South+Africa&daddr=Parow+North,+Cape+Town,+South+Africa+to:Somerset+West,+Cape+Town,+South+Africa+to:Milnerton,+Cape+Town,+South+Africa&hl=en&ll=-33.955037,18.657532&spn=0.25032,0.528374&sll=-33.911454,18.601913&sspn=0.250448,0.528374&geocode=FczB-_0dzIkcASlBKWkzGlfMHTFTuxOUSmpCAw%3BFQTi-v0d5oMbASld145qgMSWFr%3MHTG2XqBFfUG-P0dPHEfASk398T7ZbXNHTG5a6EH84n4Qg%3BFVU8-_0doEkaASnrz9UPVVnMHTFz2N4nnkA7XQ&oq=parow&mra=ls&t=m&z=12

推荐答案

如果你创建的网址格式为

If you create a web url in the format

http://maps.google.com/maps?saddr=[lat 1],[lon 1]&daddr=[lat 2],[lon 2]

其中[lat 1][lon 1]是起点的纬度和经度,同样[lat 2]并且 [lon 2] 是终点,并将其设置为 String,然后您可以将其发送到 intent:

where [lat 1] and [lon 1] are the latitude and longitude for the start point, and likewise [lat 2] and [lon 2] are the end point, and set it as a String, you can then send this to an intent:

Intent navIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(navigationUrl));
activity.startActivity(navIntent);

这将使用户可以选择打开Web 浏览器Google 地图导航.

This will give the user the option of opening a Web Browser, Google Maps, or Navigation.

对于多个目的地,将以下内容添加到 url 的末尾(对于每个额外的地方)

For multiple destinations add the following to the end of the url (for each additional place)

+to:[lat 3],[lon 3]

根据需要.

因此,对于 4 个目的地,您将拥有:

So for 4 destinations you would have:

http://maps.google.com/maps?saddr=[lat 1],[lon 1]&daddr=[lat 2],
  [lon 2]+to:[lat 3],[lon 3]+to:[lat 4],[lon 4]

这篇关于Android 导航意图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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