removing previous marker before adding new marker in google maps

Viewed 20471

I have below code to display marker in the place that I click on map. Its working perfectly and the thing is I want to remove the previous map marker when adding new marker. Where I should make changes to work perfectly.

       google.maps.event.addListener(map, "click", function (e) {

                    latLng = e.latLng;

                    console.log(e.latLng.lat());
                    console.log(e.latLng.lng());

                    image = clientURL + "/common/images/markers/red.png";
                    console.log("Marker");
                    marker = new google.maps.Marker({
                        position: latLng,
                        map: map,
                        icon: image
                    });


                });

I refered many links that was not working for my case To remove previous markers before adding new Markers

3 Answers
Related