我有这个代码,在同一个html页面中有两个脚本。第一个是包含谷歌地图的div,一旦用户点击地图上的标记,标记上的人的名字应出现在另一个div上。
<div id = "first">
<div id ="map">
<script type="text/javascript>
[.. google map api code]
var marker = new google.maps.Marker({
position: pos3,
map: map,
icon: "../images/RFlogo.png",
// name = "roger",
// lastname = "federer",
});
marker.addListener('click', function () {
//
});
</script>
</div>
</div>
<div id ="second">
<script type="text/javascript">
write.document("Name: " + name + "\nLast name: " + last name);
//how can i do to print the name on the marker ?
</script>
</div>
答案 0 :(得分:0)
使用标记的customInfo
属性完成。
var marker = new google.maps.Marker({
position: uluru,
map: map,
customerInfo:{name:"Vignesh"}
});
google.maps.event.addListener(marker,"click",function(){
console.log(this.customInfo.name);
});