显示mysql表数据在信息窗口谷歌地图API


Display mysql table data in info window Google map API

我对google MAPS API很陌生,我喜欢得到一些帮助。我画多边形在我的网站从mysql数据库使用ajax和它的工作很好。Ajax代码

function checkbox(clicked_id)
    {   
        var checkbox = document.getElementById(clicked_id);
        if(checkbox.checked==true)
        {
             // coordintaes for routes 
            // Get coordinates of route and display it
            for(m=1;m<=36;m++){
                //alert(m);
            $.ajax({
            url: "route_query4district1.php?id="+m,
            dataType: 'json',
            success: function (msg1) 
            { 
            xarray1 = new Array();
             yarray1 = new Array();
             color1 = new Array();
             new_id = new Array();
             dist_name = new Array();
            js_data1 = eval(msg1);
                //alert(js_data1);
                var k1=0;
                for(j1=0;j1<js_data1.length;j1+=5){
                xarray1[k1] = js_data1[j1];
                yarray1[k1] = js_data1[j1+1];
                color1[k1] = js_data1[j1+2];
                new_id[0] = js_data1[j1+3];
                dist_name[0] = js_data1[j1+4];
                k1++;
                }
            //alert(dist_name);
                var flightPlanCoordinates = new Array();
                for(i=0;i<xarray1.length;i++){
                 flightPlanCoordinates[i] = new google.maps.LatLng(yarray1[i], xarray1[i]);
                }
                var line_color="#00000";
                var stroke_color=line_color.toString();
                var linee_color=color1[m];
                var strokee_color=linee_color.toString();
                flightPath[m] = new google.maps.Polygon({
                    path: flightPlanCoordinates,
                    strokeColor: stroke_color,
                    fillColor: strokee_color,
                    strokeOpacity: 1.0,
                    strokeWeight: 4

              });
              flightPath[m].setMap(map);
             google.maps.event.addListener(flightPath[m], 'click', showArrays);
            infoWindow = new google.maps.InfoWindow();      
            } 
            });
            }
        }

现在我想显示与信息窗口谷歌地图APi中的每个多边形关联的属性数据。我怎么能做到呢?我想显示以下信息。名称保存在几何表中,并具有唯一的id,通过该id将几何与其他表相关联。$ sign被用作PHP变量,通过它从数据库中获取数据

名称:美元的名字,人口:$流行面积:美元区

你可以试试

flightPath[m] = new google.maps.Polygon({
                    path: flightPlanCoordinates,
                    strokeColor: stroke_color,
                    fillColor: strokee_color,
                    strokeOpacity: 1.0,
                    strokeWeight: 4,
                    id: m
              });  
//Create the info window
var infowindow = new google.maps.InfoWindow({
    width:...,
    ...
});
//Add it to object with the same key as your flightpaths
infowindows[m] = infowindow.
//Set event listener for mouse over
google.maps.event.addListener(flightPath[m], 'mouseover', function(){
    setContent(this.id);
});
google.maps.event.addListener(flightPath[m], 'mouseout', function(){
    infowindows[this.id].close();
});
//mouseover function
var setContent = function(id)
{
    //build your html. This is where you'd get your variables from php. Ajax or save them to a js variable.
    infowindows[id].setContent(html);
    infowindows[id].open(map, flightPath[id]);
};