Reputation: 3716
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
the second picture .. on the other side of street also will output 40.714 # -74.009
i have to go all the way down here , to see it change
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
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