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());
}