I would like to detect after user move where the center of the map is. Currently I have this piece of code responsible for detecting what is the latitude and longitude of beginning of the mouse move:
var lat, lng;
mymap.addEventListener('mousemove', function(ev) {
lat = ev.latlng.lat;
lng = ev.latlng.lng;
});
document.getElementById("mapid").addEventListener("click", function (event) {
console.log(lat + ' - ' + lng);
return false;
});
Unfortunately it is not working as I'd imagine. I tried to find some event responsible for stopping of moving and beside drag end event which is only for markers, not just move I couldn't find such. Also the second problem would be then - how to detect the center of map.
Does anyone has any solution for this?
I would like to detect after user move where the center of the map is. Currently I have this piece of code responsible for detecting what is the latitude and longitude of beginning of the mouse move:
var lat, lng;
mymap.addEventListener('mousemove', function(ev) {
lat = ev.latlng.lat;
lng = ev.latlng.lng;
});
document.getElementById("mapid").addEventListener("click", function (event) {
console.log(lat + ' - ' + lng);
return false;
});
Unfortunately it is not working as I'd imagine. I tried to find some event responsible for stopping of moving and beside drag end event which is only for markers, not just move I couldn't find such. Also the second problem would be then - how to detect the center of map.
Does anyone has any solution for this?
Share Improve this question edited Nov 13, 2018 at 20:37 jww 102k103 gold badges441 silver badges941 bronze badges asked Jan 24, 2018 at 21:18 sebap123sebap123 2,6857 gold badges49 silver badges85 bronze badges 1- 1 The answer to your question is here: stackoverflow./a/68362453/1243247 – João Pimentel Ferreira Commented Jul 13, 2021 at 12:36
1 Answer
Reset to default 15If you want to keep track of the center of the map, you should be using mymap.getCenter()
instead of ev.latlng
.