Google maps api 3 jquery ui映射v3:以编程方式打开信息窗口

Google maps api 3 jquery ui映射v3:以编程方式打开信息窗口,google-maps-api-3,Google Maps Api 3,好的,我有一个动态生成的google地图(使用jquery ui map v3插件)。 要显示的地图数据取决于用户输入/选择。 我这样打开地图: map_lat = parseFloat(xxxxxxxxxx); map_long = parseFloat(xxxxxxxxxxxx); map_zoom = parseInt(xxxxxxxxxxxx); myCenter = map_lat+","+map_long; myCenter = myCen

好的,我有一个动态生成的google地图(使用jquery ui map v3插件)。
要显示的地图数据取决于用户输入/选择。

我这样打开地图:

    map_lat = parseFloat(xxxxxxxxxx);
    map_long = parseFloat(xxxxxxxxxxxx);
    map_zoom = parseInt(xxxxxxxxxxxx);

    myCenter = map_lat+","+map_long;
    myCenter = myCenter.toString(); 

    $("#my_map").width(600).height(620);

    $("#my_map").gmap({
        "center": myCenter, 
        "zoom": map_zoom,
        "disableDefaultUI": false
    });
    populateMap( *varius options here* );
使用标记和数据填充我的地图的功能是:

function populateMap( *varius options here* );
{
    var htmlData = "", // will hold a list of links for user to interact. Each link must open appropriate marker info window
        htmlDataShow = '' // will hold some html data along with the link list
    ;   


    $("#my_map").gmap("clear", "markers");
    $("#point-view").hide();

    $.getJSON( "path_to_json_file", function(data) 
    { 
        $.each( data.markers, function(i, marker) 
        {
            htmlData += '<a href="javascript:void(0)" onClick=\'openGMarker("'+marker.id+'")\'>'+marker.title+'</a>&nbsp;&nbsp;';

            $("#my_map").gmap("addMarker", 
            { 
                "position": new google.maps.LatLng(marker.latitude, marker.longitude), 
                "bounds": true ,
                "icon": marker.icon,
                "id":marker.id,
            }).click(function() 
            {
                $("#my_map").gmap("openInfoWindow", { "content": marker.content }, this);
            });
        });



        htmlDataShow = '<h2 class="fut20 white lightStripTitleFull">Select a point to view on map</h2><div class="graystrip"><p>'+htmlData+'</p></div>';
        $("#point-view").empty().html(htmlDataShow).show();


    });
}
此函数将获取链接/标记的id,并打开适当的信息窗口。 我设法得到了id部分,但到目前为止我还不知道如何打开信息窗口。


感谢您的帮助。

通过提供一个工作示例,我认为您可以解决您的问题

这里有一个例子,你可以更好地理解它

var infowindow = new google.maps.InfoWindow({
    content: contentString
});

var marker = new google.maps.Marker({
    position: myLatlng,
    map: map,
    title: 'Food Waste and Organics workshop'
});
infowindow.open(map, marker);
要按语法打开
信息窗口
,请添加一个单击侦听器

google.maps.event.addListener(marker, 'click', function(event) {
    infowindow.open(map, marker);
});
这是一个基本的例子,如果可能的话,制作你自己的小提琴并提供链接


希望你明白我的意思。

是的,我在另一篇文章中找到了这个示例,但我无法将其用于我的代码。@andrew制作一个JSFIDLE并提供链接。这样我就可以检查你的代码了。同时,让我试着为你做一把小提琴。
google.maps.event.addListener(marker, 'click', function(event) {
    infowindow.open(map, marker);
});