0
I would like to know how to add markers to the map by clicking on a point on google maps. Actually create/add the marker "manually" I already know, what I would really like is to trigger the function of adding the marker by passing the latitudes and longitudes as parameter when clicking on the map. Here’s what I’ve done so far:
var mapa;
criarMapa();
function criarMapa() {
var latLng = {lat: -8.063074, lng: -34.871129};
mapa = new google.maps.Map(document.getElementById('mapa'), {
zoom: 18,
center: latLng
});
var marcador = new google.maps.Marker({
position: latLng,
map: mapa
});
}
function adicionarMarcador(latitude, longitude) {
var marker = new google.maps.Marker({
position: new google.maps.LatLng(latitude, longitude),
map: mapa
});
}
Could someone help me with this?
It worked right here buddy. Thank you very much!
– CloudAC