当用户单击链接时如何打开移动设备的地图应用程序? [英] How to open a mobile device's map app when a user clicks on a link?

查看:20
本文介绍了当用户单击链接时如何打开移动设备的地图应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个网络应用程序,如果用户点击链接,它应该打开一个地图.我能想到的最佳解决方案是使用 target="_blank" 属性打开一个新的标签/窗口到谷歌地图.

I have a web app where if a user clicks on a link it should open up a map. The best solution that I can think of is to open up a new tab/window to google maps using the target="_blank" attribute.

但我认为最好打开设备的地图应用而不是谷歌地图.

But I think that it would be best to open up the device's map app instead of google map.

我知道您可以让用户的电话应用程序在用户单击带有指向 tel:<电话号码> 的 href 属性的电话号码时弹出.我想知道地图应用程序是否也可以这样做.

I know that you can have the user's phone app to pop when the user clicks on a phone number with the href attribute pointing to tel:<the phone number>. I am wondering if this is also possible with the map app.

有没有办法让锚标签在用户点击时打开移动设备的地图应用程序?

Is there a way to allow an anchor tag to open the mobile device's map app when the user clicks it?

推荐答案

您可以使用 GEO URI Scheme地理:纬度,经度";由 RFC 5870 在链接中指定,例如

You can use the GEO URI Scheme "geo:latitude,longitude" specified by RFC 5870 in a link such as

<a href="geo:124.028582,-29.201930" target="_blank">Click here for map</a>

还有 comgooglemaps:,它推出了 iOS 版 Google 地图应用,例如:

There's also the comgooglemaps:, which launches the Google Maps app for iOS, for example:

comgooglemaps://?center=40.765819,-73.975866&zoom=14&views=traffic

哪里

  • center:这是地图视口中心点.格式为latitude,longitude的逗号分隔字符串.
  • mapmode:设置显示的地图类型.可以设置为:standardstreetview.如果未指定,则将使用当前的应用程序设置.
  • views:打开/关闭特定视图.可以设置为:satellitetraffictransit.可以使用逗号分隔符设置多个值.如果该参数未指定任何值,则将清除所有视图.
  • zoom:指定地图的缩放级别.
  • center: This is the map viewport center point. Formatted as a comma separated string of latitude,longitude.
  • mapmode: Sets the kind of map shown. Can be set to: standard or streetview. If not specified, the current application settings will be used.
  • views: Turns specific views on/off. Can be set to: satellite, traffic, or transit. Multiple values can be set using a comma-separator. If the parameter is specified with no value, then it will clear all views.
  • zoom: Specifies the zoom level of the map.

正如 techtheatre 所说,您可以使用常规的 Apple Maps 链接来触发 Apple Maps:

And as techtheatre said, you can use a regular Apple Maps link to trigger Apple Maps:

//maps.apple.com/?q=Raleigh,NC

离开协议会自动选择正确的使用,所以如果你想要一个动态链接,你可以创建一些条件代码来改变google.comapple.com 取决于您使用的系统.

Leaving off the protocol will automatically select the correct one to use, so if you wanted to have a dynamic link you could just create some conditional code that changes the link between google.com and apple.com depending on which system you're on.

这篇关于当用户单击链接时如何打开移动设备的地图应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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