知道在Safari中使用JavaScript訪問iPhone指南針是否可行?我看到how the GPS can be accessed,但我無法弄清楚指南針。使用JavaScript訪問iPhone指南針
謝謝,一如既往!
知道在Safari中使用JavaScript訪問iPhone指南針是否可行?我看到how the GPS can be accessed,但我無法弄清楚指南針。使用JavaScript訪問iPhone指南針
謝謝,一如既往!
無法通過JavaScript訪問這些信息,除非你使用像iPhoneGap
在當時,這是真實的,在iOS 5中,你可以使用JS的羅盤航向。 https://developer.apple.com/library/safari/#documentation/SafariDOMAdditions/Reference/DeviceOrientationEventClassRef/DeviceOrientationEvent/DeviceOrientationEvent.html#//apple_ref/javascript/instp/DeviceOrientationEvent/webkitCompassHeading
謝謝,很高興知道。 – 2010-04-01 23:23:01
這個答案不再是真的,iOS 4.2提供了webkitCompassHeading,看看awoodland的答案 – ianj 2011-10-25 19:35:07
在的iOS,您可以檢索指南針值這個樣子。
window.addEventListener('deviceorientation', function(e) {
console.log(e.webkitCompassHeading);
}, false);
有關更多信息,請閱讀Apple DeviceOrientationEvent文檔。
希望這有助於。
我建議你使用LeafletJS有了這個插件
https://github.com/stefanocudini/leaflet-compass
事件和方法使用起來非常簡單。
您可以嘗試在這裏演示:
http://labs.easyblog.it/maps/leaflet-compass/
只注意到今天發表的這份W3C指南針API草案:http://dev.w3.org/2009/dap/system-info/compass.html所以,也許這種功能將會有所不同。 – 2010-04-01 23:23:55
在iOS5中,您可以通過webkitCompassHeading 訪問指南針,請查看[本文檔](https://developer.apple.com/library/safari/#documentation/SafariDOMAdditions/Reference/DeviceOrientationEventClassRef/DeviceOrientationEvent/DeviceOrientationEvent.html#//apple_ref/javascript/instp/DeviceOrientationEvent/webkitCompassHeading) – 2011-10-13 18:09:04