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

}

私が欲しいのは、それぞれの緯度と経度を示すすべてのピンに情報ウィンドウを表示することです

ありがとう

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マップのドキュメントの[情報ウィンドウ]セクションにあり、次の例が示されています。

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 に答える