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

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

问题描述

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

  https://maps.google .com / maps?saddr =伦敦& daddr =巴黎

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

 导航:伦敦到巴黎


解决方案

您可以使用地理链接在Android上打开导航应用程序。不幸的是,这在iOS下不受支持。但通常你必须记住,你不能直接控制这个链接在设备上的处理方式,正如我所说的,iOS不做任何事情,甚至可能显示无效的链接错误,并且可能有Android设备也不支持该功能。请记住,您无法确定它是否可以在任何地方使用,因此您的网站不应该依赖此功能,因此对于支持此功能的设备而言,它应该只是一个额外的可用性。
$ b

1)在原生地图应用中显示位置



你可以指定一个位置,如下所示:

  geo:longitude,laditude 

或者像这样:

  geo:street + address 

您也可以搜索如下地址:

  geo:?q =街道+地址

您还可以像这样定义缩放级别:

  geo:street + address?z = 3 

也可以像这样组合多个参数:

  geo:?q = street + address& z = 15 

但注意这不符合预期。在这种情况下,Google地图会以定义的缩放级别开始,然后开始搜索并放大目标。



此处是一些Android文档。

2)在Google地图中打开路线



您也可以使用以下链接仅显示两个地点之间的路线:

  http://maps.google.com/maps?saddr=street + adress& daddr = street + address 

坐标也适用于此:

  http://maps.google.com/maps?saddr=50,10&daddr=50,20 


 < a href =http://maps.google.com/maps?saddr=New+York&daddr=San+Francisco>路线纽约 - >旧金山< / a> 



3)立即开始导航



使用此选项,该链接会打开一个到某个位置的路线,并且设备不会显示路线,但会立即开始导航:



<$ p $

google.navigation:q = street + address

您也可以使用坐标:

  google.navigation:q = 50,10 


您可以像这样使用它:

 < a href = google.navigation:q = San + Francisco>导航到旧金山< / a> 



4)测试



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

 < ;! DOCTYPE html> 
< html>
< head>
< title> Geo Link Test< / title>
< / head>
< body>
< p>< a href =geo:50,10>位置50/10< / a>< / p>
< p>< a href =geo:Vienna>位置维也纳< / a>< / p>
< p>< a href =geo:?z = 5& q = New + York>缩放5,搜索纽约< / a>< / p>
< p>< a href =geo:?q = San + Francisco& z = 15>缩放15,搜索旧金山< / a>< / p>
< p>< a href =google.navigation:q = San + Francisco>导航到旧金山< / a>< / p>
< p>< a href =google.navigation:q = 50,10>导航至50/10< / a>< / p>
< p>< a href =http://maps.google.com/maps?saddr=New+York&daddr=San+Francisco>路线纽约 - >旧金山< / a>< / p>
< p>< a href =http://maps.google.com/maps?saddr=50,10&daddr=50,20>路线50/10 - > 50/20< / A>< / p为H.
< / body>
< / html>


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

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

解决方案

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.

1) Showing a location in a native map app

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.

Here is a little bit of Android documentation.

2) Opening a route in Google Maps

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

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

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天全站免登陆