How do I get the coordinates of the center of the displayed Google map?
When a page loads, a marker appears on the map after the geolocation is determined (html5).
Task: after it appears, when dragging the map, it must always be in the center (i.e. the map is dragged, and this marker remains in the center all the time).
3
Author: Артём Ионаш, 2016-02-18
2 answers
You can call: map.getCenter()
this will return you the Lon,Lat contents object.
And this is how you can get the coordinates by right-clicking the mouse:
google.maps.event.addListener(map, "rightclick", function(event) {
var lat = event.latLng.lat();
var lng = event.latLng.lng();
...
});
4
Author: Мстислав Павлов, 2016-02-18 18:17:37
google.maps.event.addListener(map, "dragend", function(event) {
var g = map.getCenter();
$('#lat').html(g.lat());
$('#long').html(g.lng());
coords = new google.maps.LatLng(g.lat(), g.lng());
marker.setPosition(g);
});
That's how it works!))) Thank you!
0
Author: Александр, 2016-02-19 08:37:06