max
max

Reputation: 3716

google map will output inaccurate coordinate in short range

i'm using google maps to store some locations coordinate in my database by marker drag and drop

here is how i do it :

on the api :

        google.maps.event.addListener(marker_0, "dragend", function(event) {
            updatePosition(event);
        });

here is the function

    function updatePosition(evt){

    console.log(evt.latLng.lat().toFixed(3)+' # '+evt.latLng.lng().toFixed(3));

    var lt =  evt.latLng.lat().toFixed(3) ;
    var lg =  evt.latLng.lng().toFixed(3) ;

    // posting to database  

    }

it works almost fine but it is very inaccurate in close range

the first picture as you can see will output 40.714 # -74.009

enter image description here

the second picture .. on the other side of street also will output 40.714 # -74.009

enter image description here

i have to go all the way down here , to see it change

enter image description here

so if i load map using 40.714 , -74.009 trying to show the spa it could show bus stop or hairstyle across street !

is there anyway to get the exact location even for the short range ?

Upvotes: 0

Views: 98

Answers (1)

david strachan
david strachan

Reputation: 7228

3 decimal places equates to approx 100 meters See.For your purpose you will need 6 decimal places.

function updatePosition(evt){

    console.log(evt.latLng.lat().toFixed(6)+' # '+evt.latLng.lng().toFixed(6));

    var lt =  evt.latLng.lat().toFixed(6) ;
    var lg =  evt.latLng.lng().toFixed(6) ;

    // posting to database  

    }

Upvotes: 1

Related Questions