2010-04-01 70 views
7

Biết liệu có thể truy cập la bàn iPhone trong Safari bằng JavaScript không? Tôi thấy how the GPS can be accessed, nhưng tôi không thể tìm ra la bàn.truy cập la bàn qua iPhone bằng JavaScript

Cảm ơn, như mọi khi!

+1

Chỉ cần nhận thấy dự thảo API này W3C Compass công bố ngày hôm nay: http://dev.w3.org/2009/dap/system-info/compass.html Vì vậy, có lẽ loại chức năng này sẽ đến một chút. –

+0

Trong iOS5, bạn có thể truy cập la bàn với webkitCompassHeading xem [tài liệu này] (https://developer.apple.com/library/safari/#documentation/SafariDOMAdditions/Reference/DeviceOrientationEventClassRef/DeviceOrientationEvent/DeviceOrientationEvent.html#//apple_ref/javascript/instp/DeviceOrientationEvent/webkitCompassHeading) –

Trả lời

3

Bạn không thể truy cập thông tin đó thông qua javascript, trừ khi bạn đang sử dụng một cái gì đó giống như iPhoneGap

lúc này là sự thật, trong iOS 5 bạn có thể sử dụng tiêu đề la bàn trong JS. https://developer.apple.com/library/safari/#documentation/SafariDOMAdditions/Reference/DeviceOrientationEventClassRef/DeviceOrientationEvent/DeviceOrientationEvent.html#//apple_ref/javascript/instp/DeviceOrientationEvent/webkitCompassHeading

+0

Cảm ơn, rất vui được biết. –

+1

câu trả lời này không còn đúng, iOS 4.2 cung cấp webkitCompassHeading, hãy xem câu trả lời của awoodland – ianj

3

Trên iOS, bạn có thể truy xuất giá trị la bàn giá trị như thế này.

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

Để biết thêm thông tin, hãy đọc tài liệu Apple DeviceOrientationEvent.

Hy vọng điều này sẽ hữu ích.

Các vấn đề liên quan