In my web application, I am trying to get the longitude and latitude of the marker when I click on it. Below is the code that sets the marker, and then try to get the same mark of latitude and longitude when I click on it:
var myLatlng = new google.maps.LatLng(55.68322317670628, 13.177157360327598); var marker_obj = new google.maps.Marker({ clickable: true, position: myLatlng, map: dashboard_map, zIndex: i }); marker_obj.setIcon('marker.png'); google.maps.event.addListener(marker_obj, "click", function(event) { var myLatLng = event.latLng; var lat1 = myLatLng.lat(); var lng1 = myLatLng.lng(); console.log('marker latitude: '+lat1); console.log('marker longitude: '+lng1); $.ajax({ type: 'POST', url: 'http://localhost:8888/action', data: { latitude: lat1, longitude: lng1}, success: function(result) { console.log(result); } }); });
When I click on the marker, I get the correct latitude, but the longitude is not the same. the longitude value is 13.177157360327556, the marker longitude value is 13.177157360327598. Why am I not getting the correct longitude? Thanks in advance.
source share