我有一个单独的谷歌地图v3代码。只是为了当我点击它时在我的 google fusion kml 层中显示 infowindow 信息框。昨天我的代码工作正常。我没有做任何改变。但今天我的 addListner 不工作。当我复制备份项目时,与代码相同。它又起作用了,但明天又会发生这种情况。我的 addListener 不起作用。
这是我的代码
infoBubble = new InfoBubble({
map: map,
shadowStyle: 1,
padding: 5,
borderRadius: 4,
arrowSize: 20,
borderWidth: 1,
borderColor: '#2c2c2c',
disableAutoPan: true,
hideCloseButton: false,
backgroundClassName: 'phoney',
arrowStyle: 2,
});
function get_details(mode,id,lati,lng)
{
$('#loading').show();
if (xhr != null)
{
xhr.abort();
}
xhr = $.ajax({
type: "GET",
url: "realisasi2.php?id="+id,
data: "m="+mode+"&id="+id,
success: function(ret){
ajaxres = JSON.parse(ret);
iconpos = new google.maps.LatLng(lati,lng);
psbchurndata = ajaxres.detail;
var html = psbchurndata+"<i><a class='ajax' href='#' onclick=layer22("+id+","+lati+","+lng+") style='font-family: Arial;font-size: 12px; color:#00CC29;'>Lihat Datel </a></i>";
infoBubble.setContent('<div class="infowindow"><br />'+html+'</div>');
infoBubble.setPosition(iconpos);
infoBubble.close();
infoBubble.open(map);
$('#loading').hide();
}
});
}
layer.setMap(map);
google.maps.event.addListener(layer, 'click', function(e) {
alert(JSON.stringify(e, null, 4)); //UNDIFINED not Working
var lati = e.latLng['mb'];
var lng = e.latLng['nb'];
var x = e.row['id_witel'].value;
get_details('w',e.row['id_witel'].value,lati,lng);
});
}
感谢您的帮助
最佳答案
google.maps.LatLng
没有“官方”属性 mb
和 nb
(这就是 e.latLng
是)。这些属性将由 API 内部使用,这些属性的名称可能会在下一刻、下一个小时或下一天发生变化。
要检索纬度和经度,请使用 e.latLng
的 lat()
和 lng()
方法
关于javascript - 谷歌地图 addListener 无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23757325/