您需要的是InfoWindow,其中有content 选项。
假设你有这个简单的初始化函数
initializeMap = function() {
//Common code to init the map.
//common code to create dynamic markers already give you an answer here
//https://stackoverflow.com/questions/28424854/how-can-i-create-multiple-markers-on-a-google-map
//now on the same function lets add this code
function createMarkers(){
for(var i = 0 ; i <latLong.length ; i++) {
//lati and long are declared as global variables.
lati = latLong[i].lat;
longi = latLong[i].long;
var marker = new google.maps.Marker({
position: new google.maps.LatLng(lati, longi),
map: map,
icon: 'http://Yourimagesourcehere'
});
//and this is how you call it.
myInfoWindow(marker2,map,lati,long);
}
//Function to created infoWindows.
function myInfoWindow(marker2,map,lati,long){
google.maps.event.addListener(marker2, 'mouseover', function() {
for(var i=0;i<markerArray.length;i++){
infoWindow.setContent( 'My lat is ' + lati + "my long is " + longi );
infoWindow.open(map, marker2);
}});
google.maps.event.addListener(marker2, 'mouseout', function() {
infoWindow.close();
}
}
}
就像你看到的基于另一个问题How can i create multiple markers on a google map,在这个例子中,我们添加了名为myInfoWindow 的新函数,有4个参数,marker,map,以及内容的2个变量(在这种情况下late,long)
如果您对如何初始化地图或代码的外观有疑问,我有这个DEMO,这里是Source Code,只需在infoWindow 函数中添加createMarkers 函数,它应该可以工作.
告诉我是否有效。