我的想法是使用处理地图的点击事件来创建标记。然后处理标记的单击事件以显示该标记的 lat()。但是,它总是在数组中显示最终标记的 lat()。我无法解决这个错误。请帮我解决这个问题。谢谢大家
function addMarker(location){
var goldStar = {
path: google.maps.SymbolPath.CIRCLE,
fillColor: "yellow",
fillOpacity: 0.8,
scale: 1,
strokeColor: "gold",
strokeWeight: 14
};
mar = new google.maps.Marker({
position: location,
animation: google.maps.Animation.DROP,
icon: goldStar, //or use image
title: "Hello",
map: map
});
makerArray.push(mar);
//console.log(makerArray.length);
//click_Marker(mar);
google.maps.event.addListener(mar, 'click', function(){
alert(mar.getPosition().lat());
});}
function initialize(){
var mapOptions = {
zoom: 12,
overviewMapControl: false,
mapTypeId: google.maps.MapTypeId.ROADMAP,
};
map = new google.maps.Map(document.getElementById("map"), mapOptions);;
GetCurrentLocation(map);
//Hướng dẫn đi
directionDisplay.setMap(map);
directionDisplay.setPanel(document.getElementById("direction"));
getData();
showListRestaurant();
//Thêm địa điểm vào bản đồ
google.maps.event.addListener(map, 'click', function(event){
addMarker(event.latLng);
});
}