2012-12-19 138 views
-1

嗨,我一直在使用此代碼來顯示谷歌地圖上的多個位置,並且還在每個位置放置了別針。谷歌地圖信息窗口

var mylocation = new google.maps.LatLng(52.520816, 13.410186); 

var neighborhoods = [ 
new google.maps.LatLng(52.511467, 13.447179), 
new google.maps.LatLng(52.549061, 13.422975), 
new google.maps.LatLng(52.497622, 13.396110), 
new google.maps.LatLng(52.517683, 13.394393) 
]; 

var markers = []; 
var map; 

function initialize() { 
var mapOptions = { 
zoom: 12, 
mapTypeId: google.maps.MapTypeId.ROADMAP, 
center: mylocation 
}; 
map = new google.maps.Map(document.getElementById('googleMap'), 
mapOptions); 
drop(); 
} 

function drop(){ 
for (var i = 0; i < neighborhoods.length; i++) 
{ 
markers.push(new google.maps.Marker({ 
position: neighborhoods[i], 
map: map, 
})); 
} 

} 

我想是上顯示出各自的背闊肌和LNGS

感謝

+0

你想一些番茄醬或蛋黃醬,先生? – Marcelo

+0

你的代碼在這裏是不敬的。您的問題應該是:「如何使用Google API顯示信息窗口」。更好的是,只要谷歌它:) – Ross

回答

1
function drop() 
{ 
for (var i = 0; i < neighborhoods.length; i++) 
{ 
    var marker= new google.maps.Marker({ 
    position: neighborhoods[i], 
    map: map, 
    }); 
    var infoWindow = new google.maps.InfoWindow({content:marker.getPosition()}); 
    infoWindow.open(map, marker); 
} 
} 
0

的所有引腳信息窗口所有你需要的是谷歌地圖文檔中,在InfoWindow section的信息,他們表示這個例子:

var myLatlng = new google.maps.LatLng(-25.363882,131.044922); 
var mapOptions = { 
    zoom: 4, 
    center: myLatlng, 
    mapTypeId: google.maps.MapTypeId.ROADMAP 
} 

var map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions); 

var contentString = '<div id="content">'+ 
    '<div id="siteNotice">'+ 
    '</div>'+ 
    '<h2 id="firstHeading" class="firstHeading">Uluru</h2>'+ 
    '<div id="bodyContent">'+ 
    '<p><b>Uluru</b>, also referred to as <b>Ayers Rock</b>, is a large ' + 
    'sandstone rock formation in the southern part of the '+ 
    'Northern Territory, central Australia. It lies 335 km (208 mi) '+ 
    'south west of the nearest large town, Alice Springs; 450 km '+ 
    '(280 mi) by road. Kata Tjuta and Uluru are the two major '+ 
    'features of the Uluru - Kata Tjuta National Park. Uluru is '+ 
    'sacred to the Pitjantjatjara and Yankunytjatjara, the '+ 
    'Aboriginal people of the area. It has many springs, waterholes, '+ 
    'rock caves and ancient paintings. Uluru is listed as a World '+ 
    'Heritage Site.</p>'+ 
    '<p>Attribution: Uluru, <a href="http://en.wikipedia.org/w/index.php?title=Uluru&oldid=297882194">'+ 
    'http://en.wikipedia.org/w/index.php?title=Uluru</a> (last visited June 22, 2009).</p>'+ 
    '</div>'+ 
    '</div>'; 

var infowindow = new google.maps.InfoWindow({ 
    content: contentString 
}); 

var marker = new google.maps.Marker({ 
    position: myLatlng, 
    map: map, 
    title:"Uluru (Ayers Rock)" 
}); 

google.maps.event.addListener(marker, 'click', function() { 
    infowindow.open(map,marker); 
});