Reputation: 1
leaflet map on my project. My marker is set to center map using lat and lng. Now I want, whenever a user will drag or move map, marker should be in center (fixed) and can get lat and lng marker.
Upvotes: 0
Views: 1226
Reputation: 1073
It would be better if you show us some code, but I think you should have something similar to this to make marker snap to the center of the map:
let marker = L.marker(myMap.getCenter(), { icon: hyperMarker }).addTo(myMap)
Now you can use this method make the marker snap to the center of the map whenever move
event happens:
myMap.on('move', (event) => {
marker.setLatLng(myMap.getCenter())
this.markerLatLang = marker.getLatLng()
})
Upvotes: 1