-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,
}));
}

}

我想要的是在所有引脚上显示信息窗口,显示它们各自的 lats 和 lngs

谢谢

4

2 回答 2

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);
 }
}
于 2012-12-19T09:38:00.983 回答
0

您需要的所有信息都在 Google 地图文档的InfoWindow 部分中,其中显示了此示例:

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);
});
于 2012-12-19T09:10:08.457 回答