地理定位HTML5 API enableHighAccuracy:True不强制GPS在Android设备上打开



我正在构建一个移动网站,需要从用户的手机获取高精度的位置。我使用HTML5 Geolocation . watchposition函数和enableHighAccuracy: true.

在IOS设备上测试时,代码强制GPS打开并返回高精度数据(4m),但当我尝试使用MotoX (kitkat)和Nexus 5时,位置符号出现在手机顶部栏,返回的精度很低(100m)。

我还注意到的是,即使www.maps.google.com不能初始化我的手机的GPS(只使用从wifi+网络推断的位置),虽然所有的本地应用程序(包括谷歌地图应用程序)可以使用它,我的手机的位置模式设置为"高精度"。

我在以下Android浏览器上进行了测试,打开和关闭wifi,结果相同:专门,歌剧经典歌剧海豚

My JS conde:

navigator.geolocation.watchPosition(success,fail,
        { enableHighAccuracy: true,
         //timeout: 100000,
        //maximumAge: 0 
        });

,成功函数为:

function success(pos) {// Location was found
        //set global variables with coordinates
        globalLat=pos.coords.latitude;
        globalLng=pos.coords.longitude;
        $("#precision").html=pos.coords.accuracy;
        alert(pos.coords.accuracy);
        //create google location from coordinates
        latlng=new google.maps.LatLng(globalLat, globalLng);
        //send location to server and get response every 6 seconds;
        setInterval(function(){SendAndGetLocation();}, 6000);
        //create map or update it's center in case it was already created
        if(googleMap===undefined){
            createMap();
        }else{
            googleMap.setCenter(latlng); 
        }
        //Draw user's location on map
        drawLocalMarker(globalLat, globalLng);
    }

有人能想到可能发生了什么吗?

欢呼

不要被GPS误导,我的意思是不要假设它会给你准确的结果,考虑应用程序被墓碑,或者设备要睡觉,在这种情况下,网络提供商的准确性有时更准确,我自己也在做类似的事情,放弃了高精度,因为这些原因

http://www.andygup.net/how-accurate-is-html5-geolocation-really-part-2-mobile-web/这http://www.andygup.net/six-most-common-use-cases-for-android-gps/

同样在这里,moto x 4.4与高精度html5地理定位不打开chrome中的GPS。它曾经在旧的安卓系统上运行。当我启动应用程序,请求gps与android原生api html页面开始获得高精度的信息…这就是为什么html5应用很难起飞的原因,因为我们不能依赖行为

解决方法:我将把(chromium webview) html5应用/页面包装到原生android应用,并通过javascript调用/内部处理通信发送真实的地理位置

最新更新