单击时将标记添加到 Google 地图 [英] Add marker to Google Map on Click
本文介绍了单击时将标记添加到 Google 地图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我很难找到一个非常简单的示例,说明如何在用户左键单击地图时向 Google 地图添加标记.
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.
过去几个小时我环顾四周,并查阅了 Google Maps API 文档,希望得到一些帮助!
I have looked around for the past couple of hours, and consulted the Google Maps API documentation, and would appreciate some help!
推荐答案
经过深入研究,我设法找到了解决方案.
After much further research, i managed to find a solution.
google.maps.event.addListener(map, 'click', function(event) {
placeMarker(event.latLng);
});
function placeMarker(location) {
var marker = new google.maps.Marker({
position: location,
map: map
});
}
这篇关于单击时将标记添加到 Google 地图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文