Answer the question
In order to leave comments, you need to log in
Is it possible to remove a geocoded tag from a google map?
Hello everyone, I entered a certain address into the text field, clicked the button and put a mark on the map. She got up not quite exactly and I need to implement the ability to add a new label on click (the label on the map is always the same). I can't seem to remove the tag that I geocoded first, how can I do that?
let geocoder, map
let markers = []
map = new google.maps.Map(document.getElementById('map'), {
center: { lat: 56.882993, lng: 60.639189999999985 },
zoom: 16
})
map.addListener('click', function(event) {
addMarker(event.latLng)
})
function addMarker(location) {
clearMarkers()
const marker = new google.maps.Marker({
position: location,
map: map
});
markers.push(marker)
}
function setMapOnAll(map) {
for (let i = 0; i < markers.length; i++) {
markers[i].setMap(map)
}
}
function clearMarkers() {
setMapOnAll(null)
}
geocoder.geocode({ 'address': address }, function(results, status) {
if (status === 'OK') {
map.setCenter(results[0].geometry.location)
constmarker = new google.maps.Marker({
map: map,
position: results[0].geometry.location
})
} else {
console.log('Геокодер ничего не нашел. Статус ошибки: ' + status)
}
})
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question