简体   繁体   中英

Not getting accurate position using gps in javascript

I developed a demo app using Ionic framework and AngularJS

i am facing problem with location, I am not getting accurate results. The Location is changed. eg I am walking on road and its show my location outside of the road.

I get accurate position results using Google Maps App on the same device/phone, but don't get accurate results using this code. It is off by about 100m

Here is my code..

navigator.geolocation.getCurrentPosition
(
    GetCurrentLocation, 
    geo_error, geo_options, 
    {desiredAccuracy:1, maxWait:function geo_error() {
        alert("Sorry, no position available.");
    }

    var geo_options = 
    {
       enableHighAccuracy: true, 
       maximumAge        : 1000, 
       timeout           : 27000
     };

function GetCurrentLocation(post){
    console.log(pos);
}

I found many solutions on stack-overflow and on google, but problem is not resolved.

How does the API work?

Depending on which browser you are using, the HTML5 Geolocation API approximates location based on a number of factors including your public IP address, cell tower IDs, GPS information, a list of Wifi access points, signal strengths and MAC IDs (Wifi and/or Bluetooth). It then passes that information to a Location Service usually via an HTTPS request which attempts to correlate your location from a variety of databases that include Wifi access point locations both public and private, as well as Cell Tower and IP address locations. An approximate location is then returned to your code via a JavaScript callback.

You can't fix this by tweaking configurations. really depends on your actual location. Google mostly gives more accurate values because in general, they simply know more :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM