0
我正在建立基於谷歌地圖的網站,我試圖集成一個指南針(獲得移動絕對標題),但問題是,我得到一個絕對標題只爲iPhone,而android總是給我相對的標題,以我加載頁面的方向。JS HTML檢測/獲取指南針標題爲Android
我該如何獲得相對於北方的android標題?
這裏是我現在的代碼:
if (window.DeviceOrientationEvent && mobile) {
window.addEventListener('deviceorientation', function(event) {
var dir;
if (event.webkitCompassHeading) {
// Apple works only with this, alpha doesn't work
dir = event.webkitCompassHeading + 180;
} else {
//tried also event.alpha...
dir = event.absolute;
}
var arrowPath = {
path: 'M -50 120 L 50 120 L 000 170 z',
fillColor: black,
fillOpacity: 1,
scale: 0.1,
strokeOpacity: 0,
strokeColor: 'white',
strokeWeight: 1,
rotation: dir
};
userDirection.setIcon(arrowPath);
});
}
可能的重複[我可以使用Javascript來獲取指南針標題爲iOS和Android?](https://stackoverflow.com/questions/16048514/can-i-use-javascript-對獲得最羅盤航向換IOS-和機器人) –