首页 文章

我们怎样才能在PhoneGap中获得准确的纬度和经度?

提问于
浏览
-1

我正在尝试使用PhoneGap获得准确的纬度和经度,但我无法获得准确的lat,长期它总是在第三个小数点后波动意味着它给出了11m的差异,如下所述:小数位度距离------- ------- -------- 0 1 111 km 1 0.1 11.1 km 2 0.01 1.11 km 3 0.001 111 m 4 0.0001 11.1 m 5 0.00001 1.11 m

为了获得lat,长期在phonegap我使用gpsdetect插件的地理位置插件 .

这是代码:navigator.geolocation.getCurrentPosition(onSuccess,onError,{maximumAge:3000,timeout:20000,enableHighAccuracy:true}); function onSuccess(position){window.lat = position.coords.latitude; window.long = position.coords.longitude; var accuracy = position.coords.accuracy; var lat =(window.lat).toFixed(6); var long =(window.long).toFixed(6); . 的document.getElementById( 'LAT')值=纬度; . 的document.getElementById( '长')的值=长; . 的document.getElementById( '精度')值=准确性;函数onGPSError(e){console.log(“错误:”e); }

使用这个代码我得到(22.699737,75.867208)但实际上是(22.699667,75.86729) .

我只想根据gps获取位置而不是来自手机信号塔和wifi信号 .

当gps打开时,是否可以通过GPS获取位置?

1 回答

  • 0

    你可以使用jquery geocode从地址获取lat .

    从GPs传递您的位置(地址)并调用此jquery函数,您将获得完美的lat,long .

    var geocoder = new google.maps.Geocoder();

    geocoder.geocode({ 'address': address }, function (results, status) {
    
        if (status == google.maps.GeocoderStatus.OK) {
            map.setCenter(results[0].geometry.location);
            var marker = new google.maps.Marker({
                map: map,
                position: results[0].geometry.location,
                title: results[0].formatted_address
            });
            var infowindow = new google.maps.InfoWindow({ content: address });
            infowindow.open(map, marker);
            google.maps.event.addListener(marker, 'click', function () { infowindow.open(map, marker); });
        } 
        else{
            alert("Problem with geolocation");
        }
    });
    

    将地址转换为纬度经度:https://github.com/dhavaldenny/mapgeocodeangular

相关问题