24
Views
2
Comments
[Google Maps Web] How to create only one marker when click in map?
google-maps-web
Web icon
Forge asset by Labs
Application Type
Traditional Web

I have a map and a event to create a marker when user clicks on the map, but I wish that only one marke could be created at time. After user clicks on the map and create a marker, if he makes it again, the previous marker should disappear and only the new one will be avaiable.

Here it's the code that I have on my preparation:


UserImage.jpg
vikas sharma
Champion

Hi,

So to have only one marker, you can follow 2 approaches :

1. Either remove first marker or all other markers and add new one.

2. Update the position of first marker.

So above logic is correct. You just need to check if already a marker is there or not. If there, then update it.

regards

UserImage.jpg
Tia Thomas

Hi, you can try this way: Place the eventListener inside the map initialize function & introduce a counter variable and you can use it inside addListing variable.


Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.