Add marker to Google Map on Click

前端 未结 6 1931
有刺的猬
有刺的猬 2020-12-12 09:50

I\'m surprisingly struggling to find a very simple example of how to add a marker(s) to a Google Map when a user left clicks on the map.

I have looked around for the

6条回答
  •  清歌不尽
    2020-12-12 10:22

    Currently the method to add the listener to the map would be

    map.addListener('click', function(e) {
        placeMarker(e.latLng, map);
    });
    

    And not

    google.maps.event.addListener(map, 'click', function(e) {
        placeMarker(e.latLng, map);
    });
    

    Reference

提交回复
热议问题