【问题标题】:How do i place a marker at each coordinate point of a polygon?如何在多边形的每个坐标点放置标记?
【发布时间】:2012-05-10 09:17:00
【问题描述】:

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

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

【问题讨论】:

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


    【解决方案1】:

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

    See here for making markers

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

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

    这是来自 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 循环,其中 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]);
    });
    }
    

    希望对你有帮助!!

    【讨论】:

    • 您好,我已经在多边形的每个点创建了标记,但我仍然需要为每个标记创建一个信息窗口。任何人都可以帮忙。我很接近,但它一定是我忘记的简单事情。见链接sugarcube.ie/TEST/googlemaps/conor/polygonPoints.html
    • 您好,看看您的代码,我认为您的问题是您正在尝试动态更改单个信息窗口的对话框,每个标记点应该在其中还有一个相应的信息窗口对象(即您为您拥有的每个标记创建一个新的信息窗口),因此您应该有一个信息窗口和标记数组,并在您的 for 循环中将每个标记绑定到自己的信息窗口。
    猜你喜欢
    • 1970-01-01
    • 2021-12-05
    • 1970-01-01
    • 2016-03-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-05
    • 2015-02-27
    相关资源
    最近更新 更多