0
我正在嘗試使用ajax和php的組合動態地爲我的Google地圖添加標記。 代碼的第一部分將latlng發送到php文件。 PHP文件然後返回所需的標記位置。向Google地圖動態添加標記
當我提醒返回部分(警告測試以確保PHP處理的數據正確)時,它看起來不錯,但我似乎不能將返回的標記添加到我的地圖。
查看下面的代碼。
//將數據發送到URL(發送到PHP文件) //返回數據的位置標記(這是返回PHP文件產生)
非常感謝,
//將數據發送到URL
var xmlHttp = getXMLHttp();
xmlHttp.onreadystatechange = function() {
if (xmlHttp.readyState == 4) {
HandleResponse(xmlHttp.responseText);
}}
xmlHttp.open("POST",'MYPHPFILE',true);
xmlHttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlHttp.send("LATLON="+strLAT);
//返回數據的位置標記
var wxlatlng = new google.maps.LatLng(52,1);
var marker = new google.maps.Marker({
position: wxlatlng,
map: map,
icon: '../../icons/flags/traffic_light_red.png',
title: 'TEST', });
//返回數據的位置標記
var wxlatlng = new google.maps.LatLng(52,1.1);
var marker = new google.maps.Marker({
position: wxlatlng,
map: map,
icon: '../../icons/flags/traffic_light_red.png',
title: 'TEST', });
//警告測試,以確保PHP處理的數據正確
function HandleResponse(response) {
document.getElementById('ResponseDiv').innerHTML = response;
alert($('#ResponseDiv').text());
}