需要从移动 Web 应用程序链接到本机映射的新方法



我的移动网络应用程序使用地图链接,只需链接到"maps.google.com/maps?q=[某物]"即可自动启动Android或iPhone的地图功能。 iOs 6问世,链接停止工作,因为苹果希望我们使用"地图"。苹果.com"。所以现在我必须专门检测 iOs 6 并交换链接。

有没有一种干净的方法可以从适用于Android,iOs 6和iOs pre-6的移动Web应用程序打开设备/本机映射应用程序,因为iOs 6使它感到紧张?

事实证明,您发送到"maps.apple.com"的任何内容都会转发到"maps.google.com"!

这两个链接都指向同一个地方

http://maps.google.com/maps?q=New+York

http://maps.apple.com/maps?q=New+York

苹果开发网站上最近更新的文档...http://developer.apple.com/library/ios/#featuredarticles/iPhoneURLScheme_Reference/Articles/MapLinks.html#//apple_ref/doc/uid/TP40007894-SW1

我在iPhone上尝试过这个,maps.apple.com 确实启动了新的Apple Maps应用程序(但是我只在地址栏中输入了它)。当我使用 Chrome 在 iMac 上点击相同的链接时,我被重定向到 maps.google.com。我相信这是苹果有意为之的。如果您的目标是使用iOS 6的iPhone,那么您将需要从 google.com 切换到 apple.com。它应该是无缝的。

[已确认 - 这适用于装有iOS 6.0的iPhone-我不再有iOS 5.x设备来确认这在以前版本的iOS上重定向。它确实在 Safari 中进行重定向,但在 iPhone 模拟器中被破坏]

// javascript snippet to detect ipad/iphone OS version - these are notoriously fragile, use at your own risk :)
function getOsVersion() {
var osVersion = window.navigator.userAgent.match(/(ipad|iphone);s+cpus.*oss+([_0-9]+)/i);
if (osVersion && osVersion.length === 3) {
    return Number(osVersion[2].replace('_', '.'));
}
return 0;

}

在 Android 中,您可以使用以下 Intent URI:

geo:latitude,longitude
geo:latitude,longitude?z=zoom
geo:0,0?q=my+street+address
geo:0,0?q=business+near+city

例如:

String uri = "geo:37.167629,-121.222478";
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri) );
startActivity(intent);

最新更新