相关疑难解决方法(0)

Geolocation HTML5 enableHighAccuracy True,False还是Best Option?

我有关于HTML5地理定位功能的问题.我使用下面的代码来获取位置数据.我使用"enableHighAccuracy:false"选项来使用基于Cell的GPS功能.准确度很低但响应速度太快.但有些人总是在手机上使用内置GPS,因此这段代码对他们不起作用.如果我将accurency选项更改为"enableHighAccuracy:true",则它适用于他们.但这次,代码仅使用内置GPS.不是基于CELL的GPS.

问题 - >我怎么能这样做:首先,尝试从内置GPS获取超时(例如5000ms)的位置如果此时无法获得位置只需查找基于单元格的位置超时(例如10000ms)如果位置不能在这个时候得到,返回一条错误信息.

这是我现在使用的代码.

提前致谢.

    function getLocationfromGoogle() {
    navigator.geolocation.getCurrentPosition(
      function(pos) {
        $("#lat_field").val(pos.coords.latitude);
        $("#long_field").val(pos.coords.longitude);
        var geocoder = new google.maps.Geocoder();
        var latLng = new google.maps.LatLng(pos.coords.latitude,pos.coords.longitude);
              geocoder.geocode({ 'latLng': latLng}, function (results, status) {
              if (status == google.maps.GeocoderStatus.OK) {
                //console.log(results[0].formatted_address);
                $("#adresim").val(results[0].formatted_address);
                }
                else {
            alert('Google convertion is not succesfully done.');  

            }
            });
      },function error(msg){

                alert('Please enable your GPS position future.');  

      },{maximumAge:600000, timeout:5000, enableHighAccuracy: false}

    ); 
    }
Run Code Online (Sandbox Code Playgroud)

html5 geolocation

12
推荐指数
2
解决办法
4万
查看次数

标签 统计

geolocation ×1

html5 ×1