0

如前所述,我正在使用 JQuery Map UI 插件,并且很难弄清楚如何获得位置列表,一旦单击,将在地图中打开信息窗口。

这是我的工作代码,用于拉入地图标记并输出地图外的位置列表。

$.getJSON( 'data.php', function(data) {
$.each( data.markers, function(i, m) {
    var temp = m.services.split(',');
    $('#map_canvas').gmap('addMarker', {
        'position': new google.maps.LatLng(m.lat, m.lng),
        'bounds': true,
        'services':temp
    }).click(function() {
       $('#map_canvas').gmap('openInfoWindow', { 'content': m.address }, this);
    });
   //list of locations that once click, will open the map info window
    $('ul.list').append('<li><a href="#" >' + m.address + '</a></li>');
});
});

截至目前,上述内容仅允许地图内的实际标记打开信息窗口。非常感谢任何有关使 UL 项目列表可单击并打开信息窗口的帮助/指导。

4

1 回答 1

1

我可能的方式(可能还有其他方式):

google.maps.Marker-instance 存储为 -element 的属性<li>,因此您可以在单击此元素时访问它并触发对标记的单击:

$.each( data.markers, function(i, m) {
    var temp = m.services.split(',');

    var marker=//<--create a local variable
          $('#map_canvas').gmap('addMarker', {
            'position': new google.maps.LatLng(m.lat, m.lng),
            'bounds': true,
            'services':temp
            }).click(function() {
                $('#map_canvas').gmap('openInfoWindow', { 'content': m.address }, this);
        })[0];//<--note the [0]

   //list of locations that once click, will open the map info window
    $('<li><a href="#" >' + m.address + '</a></li>')
      .data('marker',marker)
       .appendTo('ul.list')
        .click(function(e){
                e.preventDefault();
                google.maps.event.trigger($(this).data('marker'),'click');
              });
});
于 2013-09-18T21:52:24.830 回答