2012-03-06 22 views
1

,我在這裏有一個新的問題,我想呼應的信息窗口裏面的內容從PHP變量,有什麼建議?如何使內部的jQuery的「內容」回聲工作,在谷歌地圖信息窗口

這裏是我的代碼,裏面的信息窗口的內容我已經使用了一些HTML代碼,我有PHP變量來代替。 爲EG:deviceid1應該值替換從數據庫

var trieste = new google.maps.LatLng(45.6111555,13.8022614); 
    var mapOptions = { 
    zoom:  12, 
    center: trieste, 
    mapTypeId: google.maps.MapTypeId.ROADMAP 
    } 

    var map = new google.maps.Map($("#map_canvas")[0], mapOptions); 

    var places = 
    [ 
     { 
     "position": [45.6466883,13.7631226] 
     }, 
     { 
     "position": [45.6433281,13.7895584] 
     }, 
     { 
     "position": [45.6017884,13.6673355] 
     }, 
     { 
     "position": [45.622442,13.7641525] 
     } 
    ] 

    var currentPlace = null; 
    var icons=["green.png","red.png","blue.png","yellow.png"]; 
    var i=0; 

    $(places).each(function() { 
     var place = this; 
     var marker = new google.maps.Marker({ 
     position: new google.maps.LatLng(place.position[0], place.position[1],place.position[2],place.position[3]), 
     map  : map, 
     icon : icons[i] 
     }); 

    if(i==0) 
    { 
    var infowindow = new google.maps.InfoWindow({ 
    content: '<ul><li>Device ID1</li><li>Device configuration1</li><li>Device Description1</li></ul><a href="riacqua/activepanel.php">Goto RIACQUA</a>' 
    }); 
    google.maps.event.addListener(marker, 'mouseover', function() { 
    infowindow.open(map, marker); 
    }); 
    google.maps.event.addListener(marker, 'mouseout', function() { 
    infowindow.close(); 
    }); 
    } 
+0

它也許更多的是PHP的問題,當一個jQuery的問題。 – 2012-03-06 14:56:43

+0

我是jQuery和PHP的初學者,我認爲這是問題 – Vibing 2012-03-06 14:59:15

+0

在什麼文件是JavaScript代碼位於,外部'.js'文件,'.html'文件或'.php'文件? – jeroen 2012-03-06 15:00:55

回答

1

你只是想這樣做thsi?

var infowindow = new google.maps.InfoWindow({ 
    content: '<ul><li><?php echo $deviceId; ?></li><li>Device configuration1</li><li>Device Description1</li></ul><a href="riacqua/activepanel.php">Goto RIACQUA</a>' 
    }); 

這應該做當然的伎倆,如果你的設備ID變量包含引號/單引號,那麼你可能要剝奪他們還是難逃他們。

這應該與PHP文件沒有問題,但是你可能需要,如果你試圖讓這個在其他文件類型渲染(HTML,HTM等),以更改其他設置。

+0

好吧,我想我明白了,我會將其改爲.php .. – Vibing 2012-03-06 15:08:21

+0

很高興我能提供幫助。如果您在Apache服務器上運行,通常可以使用.htaccess文件告訴Apache爲.htm和.html文件也渲染PHP腳本(或任何文件擴展名) – shanabus 2012-03-06 15:12:41

2
content: '<ul><li><?=$deviceID?></li><li>Device configuration1</li><li>Device Description1</li></ul><a href="riacqua/activepanel.php">Goto RIACQUA</a>' 
相關問題