单击时将标记添加到Google地图 [英] Add marker to Google Map on Click
本文介绍了单击时将标记添加到Google地图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我惊奇地发现了一个很简单的例子,就是当用户在地图上点击鼠标时,如何向Google地图添加标记。 >我在过去的几个小时中查了一下,并查阅了Google Maps API文档,并希望得到一些帮助! 解决方案
经过深入研究,我设法找到了解决方案。
google.maps.event.addListener(地图,'点击' ,函数(event){
placeMarker(event.latLng);
});
函数placeMarker(location){
var marker = new google.maps.Marker({
position:location,
map:map
}) ;
}
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 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屋!
查看全文