0

我正在尝试在谷歌地图 v3 上创建一个多边形,并在多边形的每个 LatLng 点显示一个标记。当您单击任何标记时,信息窗口应显示标记所在的坐标。

到目前为止,我已经在地图上绘制了一个多边形,当您单击它时,它将显示多边形的每个坐标。我需要下一步的帮助。我想在每个点放置一个标记,当单击告诉 LatLng 坐标时将显示一个信息窗口。到目前为止我所做的链接位于http://www.sugarcube.ie/TEST/googlemaps/conor/polygonPoints.html 有人可以帮忙吗?

4

1 回答 1

1

嗨,如果您有实际设置的坐标:

看这里制作标记

另请参阅此处以获取有关标记的信息窗口

如果您需要更多帮助,请不要害怕问,我有一些示例代码,我目前无法访问它,抱歉。

以下是 google 关于如何创建信息窗口的示例代码:

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

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

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

我认为您的问题在于事件处理程序,此示例仅处理一个标记和一个信息窗口,在您的情况下,您将需要 2 个数组,一个用于所有标记,一个用于所有信息窗口,以及某种 for 循环,每个标记都有一个事件监听器被创建并且它被绑定到一个特定的信息窗口,这正是我在我的项目中必须做的,我保证我会在今天晚些时候上传代码我只是暂时无法访问它,

你正在寻找类似的东西

    var markers = new Array();
    var infowindows - new Array();

//Fill the markers with the co-ordinates needed using push method
//then

for(i=0;i<markers.length;i++)
{
   google.maps.event.addListener(markers[i], 'click', function() {
  infowindows[i].open(map,markers[i]);
});
}

希望这可以帮助 !!

于 2012-05-10T09:34:39.180 回答