如何在多边形的每个坐标点放置标记?

时间:2012-05-10 09:17:01

标签: google-maps google-maps-api-3 google-maps-markers

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

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

1 个答案:

答案 0 :(得分:1)

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

See here for making markers

另请参阅here了解有关标记的信息页

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

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

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

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

你正在找东西

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

希望这会有所帮助!!