针对Android的JS HTML检测/获取指南针标题

问题描述 投票:0回答:1

我正在构建基于谷歌地图的网站,我正在尝试整合指南针(获取移动绝对标题),但问题是我只能获得iPhone的绝对标题,而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 jquery html google-maps mobile
1个回答
-1
投票

此时此选项在Android中不可用。等待下一个Android更新8.0

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