有没有办法从移动浏览器调用导航? [英] Is there a way to invoke navigation from mobile browser?

查看:18
本文介绍了有没有办法从移动浏览器调用导航?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个非常小的 HTML5/javascript 网站,可以通过 android/iphone 等设备的移动浏览器打开.我正在使用 HTML5 的地理位置来获取当前位置,但是一旦有了,我就想导航到某个目的地.我想出的最好的方法是用户点击类似于下面链接的链接

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

https://maps.google.com/maps?saddr=london&daddr=paris

然而,这并没有打开导航应用程序,它只是切换到移动谷歌地图网站.有没有办法使用 HTML5/javascript 打开导航 (GPS) 应用程序?像这样的:

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:

navigate:London to Paris

推荐答案

您可以使用地理链接在 Android 上打开导航应用.不幸的是,iOS 不支持此功能.但通常你必须记住,你不能直接控制设备上如何处理这个链接,正如我所说的 iOS 什么都不做甚至可能显示无效链接错误,并且可能有 Android 设备也不支持这个功能.请记住,您无法确定它是否可以在任何地方使用,因此您的网站不应依赖此功能,它应该只是为支持此功能的设备提供额外的可用性.

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.

使用地理链接,您可以像这样指定位置:

With the geo link you can specify a location like this:

geo:longitude,laditude

或者像这样:

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.

这里是一些 Android 文档.

Here is a little bit of Android documentation.

您还可以使用以下链接仅显示两个位置之间的路线:

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

坐标也适用于此:

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) 立即开始导航

使用此选项,链接会打开通往某个位置的路线,设备不仅会显示路线,还会立即开始导航:

3) Immediately starting a navigation

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

你也可以使用坐标:

google.navigation:q=50,10

你会这样使用它:

<a href="google.navigation:q=San+Francisco">Navigation to San Francisco</a>  

4) 测试

我已经使用以下 HTML 在运行 Android 4.4 (KitKat) 的 Nexus 5 上测试了所有内容:

4) Testing

I have tested everything on a Nexus 5 running Android 4.4 (KitKat) with the following HTML:

<!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>

这篇关于有没有办法从移动浏览器调用导航?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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