使用JavaScript访问iPhone指南针

问题描述 投票:7回答:3

知道是否可以使用JavaScript访问Safari中的iPhone指南针?我看到how the GPS can be accessed,但我无法弄明白指南针。

iphone compass-geolocation
3个回答
3
投票

您无法通过javascript访问该信息,除非您使用的是iPhoneGap之类的内容

当时这是真的,在iOS 5中你可以使用JS中的罗盘标题。 https://developer.apple.com/documentation/webkitjs/deviceorientationevent/1804777-webkitcompassheading


3
投票

在iOS上,您可以像这样检索罗盘值。

window.addEventListener('deviceorientation', function(e) {
    console.log( e.webkitCompassHeading );
}, false);

有关更多信息,请阅读Apple DeviceOrientationEvent文档。 希望这可以帮助。


0
投票

我建议你使用LeafletJS和这个插件 https://github.com/stefanocudini/leaflet-compass

使用事件和方法非常简单。

您可以在这里尝试演示: http://labs.easyblog.it/maps/leaflet-compass/

© www.soinside.com 2019 - 2024. All rights reserved.