从 URL Apple、Android、Windows 设备打开本机地图应用程序

Opening Native Map App from URL On Apple, Android, Windows Devices

有没有人进一步详细说明如何处理多个设备。我想定位 iPhone、Android 和 Windows 设备。根据这篇文章,您可以使用不同的链接。关于如何在单个元素上使用 3 个不同的链接有什么想法吗?

http://habaneroconsulting.com/insights/opening-native-map-apps-from-the-mobile-browser#.VYg3-flVikp

我通常这样做:

var isiOS = (navigator.userAgent.match('iPad') || navigator.userAgent.match('iPhone') || navigator.userAgent.match('iPod'));
var isAndroid = navigator.userAgent.match('Android');
var isWP = navigator.userAgent.match('Windows Phone') || navigator.userAgent.match('IEMobile');

if (isiOS){
    setTimeout(function () { window.location = siteURL; }, 25);     //fall back url
    $('body').append('<iframe style="visibility: hidden;" src="'+ appURI +'" />');

} else if ((isAndroid) || (isWP)){
    setTimeout(function () { window.location = siteURL; }, 25);     //fall back url
    window.location = appURI;

} else {    // if (isOtherPlatform)
    window.location = siteURL;
}

请注意,在 iOS,您无法确定用户是否安装了地图应用程序。如果您导航到用户尚未安装的应用程序,将导致出现一条丑陋的消息,抱怨目标应用程序不存在。解决方法是在 iframe 中打开那个深度 link。

另请注意,您应始终在几秒钟后将用户重定向到地图的 Web 版本以提供流畅的流程。