我正忙于为 google maps API (v3) 创建一个脚本,几乎完成了,但我遇到了一个我不知道如何解决的问题(可能是不间断编码的时间:P) .
好吧,我正在尝试做的是创建一个 html 字符串,在该字符串中我还创建了一个按钮,我想在单击时执行一个函数,但它不起作用,控制台向我抛出这个错误:
未捕获的 ReferenceError:未定义 marker_gen
这是导致问题的代码:
(也创建按钮的ajax代码)(我用'->'标记了html字符串)
$.get("includes/require/gen.php", function (data) {
$(data).find("marker").each(function () {
//Get user input values for the marker from the form
var name = $(this).attr('name');
var info = $(this).attr('address'); //description
var type = $(this).attr('type');
var point = new google.maps.LatLng(parseFloat($(this).attr('lat')),parseFloat($(this).attr('lng')));
//call create_marker() function for xml loaded maker
//create_marker(point, name, address, false, false, false);
var marker_gen = new google.maps.Marker({
position: point,
map: map,
icon: "img/icons/green_marker.png"
})
google.maps.event.addDomListener(marker_gen,"click",function(event){
-> contentString = '<div id="div_info"><h2>'+ name+'</h2> <p><b>Type: </b>'+type+'<br/><b>Coördinaten: </b>'+point+'</p><p><b>Omschrijving:</b><br/>'+info+'<br/><br/></span><button name="remove-marker" class="remove-marker" onclick="remove_marker(marker_gen)" title="Remove Marker">Remove Marker</button></div>';
IW.content = contentString;
IW.open(map,marker_gen);
});
});
});
这是 remove_marker 函数(但怀疑它是必需的)
function remove_marker(Marker)
{
/* determine whether marker is draggable
new markers are draggable and saved markers are fixed */
if(Marker.getDraggable())
{
Marker.setMap(null); //just remove new marker
//marker = null;
}
else
{
//Remove saved marker from DB and map using jQuery Ajax
var mLatLang = Marker.getPosition().toUrlValue(); //get marker position
var myData = {del : 'true', latlang : mLatLang}; //post variables
$.ajax({
type: "POST",
url: "includes/require/gen.php",
data: myData,
success:function(data){
Marker.setMap(null);
alert(data);
},
error:function (xhr, ajaxOptions, thrownError){
alert(thrownError); //throw any errors
}
});
}
}
如果有人对此有解决方案,我很想听听。
在此先感谢,雷米