Android 有没有办法从移动浏览器调用导航?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23232273/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Is there a way to invoke navigation from mobile browser?
提问by C graphics
I am developing a very small HTML5/javascript website to be openned by mobile browsers from devices like android / iphone. I am using geo location of HTML5 to get the current location but once I have that I want to navigate to some destination. The best I came up with was that the user clicks on a link similar to the link below
我正在开发一个非常小的 HTML5/javascript 网站,由来自 android/iphone 等设备的移动浏览器打开。我正在使用 HTML5 的地理位置来获取当前位置,但是一旦我想导航到某个目的地。我想到的最好的方法是用户点击类似于下面链接的链接
https://maps.google.com/maps?saddr=london&daddr=paris
However that does not open the navigation app, it just switches to the mobile Google Maps website. Is there a way to open the navigation (GPS) app by using HTML5/javascript? Something like this:
然而,这不会打开导航应用程序,它只是切换到移动谷歌地图网站。有没有办法使用 HTML5/javascript 打开导航(GPS)应用程序?像这样的东西:
navigate:London to Paris
回答by Xaver Kapeller
You can use geo links to open the navigation app on Android. Unfortunately this is not supported under iOS. But generally you have to remember that you can't directly control how this link is handled on the device, as I said iOS does nothing or may even show an invalid link error, and there may be Android devices which also do not support this feature. Just remember that you cannot be sure if it works anywhere and as such your website should not depend on this feature, it should just be an extra bit of usability for devices which support this feature.
您可以使用地理链接在 Android 上打开导航应用程序。不幸的是,这在 iOS 下不受支持。但通常你必须记住,你不能直接控制这个链接在设备上的处理方式,正如我所说的,iOS 什么都不做,甚至可能显示无效链接错误,而且可能有 Android 设备也不支持这个功能. 请记住,您无法确定它是否可以在任何地方使用,因此您的网站不应依赖此功能,它应该只是为支持此功能的设备提供额外的可用性。
1) Showing a location in a native map app
1) 在本地地图应用中显示位置
With the geo link you can specify a location like this:
使用地理链接,您可以指定这样的位置:
geo:longitude,laditude
Or like this:
或者像这样:
geo:street+address
You can also search for an address like this:
您还可以搜索这样的地址:
geo:?q=street+address
You can also define a zoom level like this:
您还可以像这样定义缩放级别:
geo:street+address?z=3
And it is also possible to combine multiple parameters like this:
也可以像这样组合多个参数:
geo:?q=street+address&z=15
But beware that this does not work as expected. In this case in Google Maps it starts out with the defined zoom level and then starts the search an zooms in on the target.
但请注意,这不会按预期工作。在这种情况下,在谷歌地图中,它从定义的缩放级别开始,然后开始搜索并放大目标。
Hereis a little bit of Android documentation.
这里有一些 Android 文档。
2) Opening a route in Google Maps
2) 在谷歌地图中打开路线
You can also use the following link to just show a route between two locations:
您还可以使用以下链接仅显示两个位置之间的路线:
http://maps.google.com/maps?saddr=street+adress&daddr=street+address
And coordinates also work with this:
坐标也适用于此:
http://maps.google.com/maps?saddr=50,10&daddr=50,20
You can again use it like this:
您可以像这样再次使用它:
<a href="http://maps.google.com/maps?saddr=New+York&daddr=San+Francisco">Route New York --> San Francisco</a>
3) Immediately starting a navigation
3) 立即开始导航
With this option the link opens a route to a location and the device doesn't just show the route but it immediately starts navigating:
使用此选项,链接会打开通往某个位置的路线,设备不仅会显示路线,还会立即开始导航:
google.navigation:q=street+address
You can also use coordinates:
您还可以使用坐标:
google.navigation:q=50,10
You would use it like this:
你会像这样使用它:
<a href="google.navigation:q=San+Francisco">Navigation to San Francisco</a>
4) Testing
4) 测试
I have tested everything on a Nexus 5 running Android 4.4 (KitKat) with the following HTML:
我已经使用以下 HTML 在运行 Android 4.4 (KitKat) 的 Nexus 5 上测试了所有内容:
<!DOCTYPE html>
<html>
<head>
<title>Geo Link Test</title>
</head>
<body>
<p><a href="geo:50,10">Location 50/10</a></p>
<p><a href="geo:Vienna">Location Vienna</a></p>
<p><a href="geo:?z=5&q=New+York">Zoom 5, Search for New York</a></p>
<p><a href="geo:?q=San+Francisco&z=15">Zoom 15, Search for San Francisco</a></p>
<p><a href="google.navigation:q=San+Francisco">Navigation to San Francisco</a></p>
<p><a href="google.navigation:q=50,10">Navigation to 50/10</a></p>
<p><a href="http://maps.google.com/maps?saddr=New+York&daddr=San+Francisco">Route New York --> San Francisco</a></p>
<p><a href="http://maps.google.com/maps?saddr=50,10&daddr=50,20">Route 50/10 --> 50/20</a></p>
</body>
</html>
回答by David
well after a lot of link testing I have solved it for me:
经过大量的链接测试,我已经为我解决了:
<a href="http://maps.google.com/maps?q=loc:
<lat>,<lng>&navigate=yes">nav</a>
<a href="http://maps.google.com/maps?q=loc:
<lat>,<lng>&navigate=yes">nav</a>
this one is opening the user nav app choosing menu, and it pass the cords you wish to navigate to.
这是打开用户导航应用程序选择菜单,它传递您希望导航到的电线。
enjoy
请享用
回答by wlh
Since this question was first posted and answered, as of Oct. 2017, Google has developed an API called Maps URL.
自从这个问题第一次被发布和回答以来,截至 2017 年 10 月,谷歌开发了一个名为Maps URL的 API 。
It is a universal, cross-platform URL for launching google maps.
它是用于启动谷歌地图的通用跨平台 URL。
https://www.google.com/maps/dir/?api=1
is the endpoint for maps that could include navigation.
https://www.google.com/maps/dir/?api=1
是可能包含导航的地图的端点。
You add the following parameters:
您添加以下参数:
- Origin:
&origin=new+york
- Destination:
&destination=san+fransisco
- Navigation:
&dir_action=navigate
- 起源:
&origin=new+york
- 目的地:
&destination=san+fransisco
- 导航:
&dir_action=navigate
If you leave out the origin, it will detect the location of the device, which is probably better for navigation anyway:
如果您省略原点,它将检测设备的位置,这可能更适合导航:
https://www.google.com/maps/dir/?api=1&destination=san+fransisco&dir_action=navigate
https://www.google.com/maps/dir/?api=1&destination=san+fransisco&dir_action=navigate
This will not immediately open navigation, but will take you to a google map, which will have the navigation icon on the page, and will give the user the option to use the app (or download it if they don't have it). This seems like a good solution. I just tested it in my browser, my Google Pixel, and my iPhone and it works the same on each mobile device.
这不会立即打开导航,但会将您带到谷歌地图,该地图将在页面上显示导航图标,并为用户提供使用该应用程序的选项(如果他们没有,则下载该应用程序)。这似乎是一个很好的解决方案。我刚刚在我的浏览器、我的 Google Pixel 和我的 iPhone 中测试了它,它在每个移动设备上的工作方式都是一样的。
Check out the rest of the documentation for more useful features: https://developers.google.com/maps/documentation/urls/guide
查看文档的其余部分以获得更多有用的功能:https: //developers.google.com/maps/documentation/urls/guide