我在我的代码中使用了这种方法来加载标记,但它不起作用。
function loadMarkers() {
if (locations.length > 0) {
var local = locations.split(';');
for (var i = 0; i < local.length; i++) {
var center = local[i].split(',');
var iconoMarca = imagePath;
var position = new google.maps.LatLng(center[0],
center[1]);
var marker = new google.maps.Marker({
position: position,
image: iconoMarca,
optimized: false,
map: map,
draggable: true
});
}
}
}
我知道它所调用的方法是因为我使用chrome进行调试但无法查看问题所在,对我来说代码没问题。这是事件的监听者
google.maps.event.addListenerOnce(map, 'idle', loadMarkers);
thi是初始化地图的功能
function initialize() {
$(".btnSaveMarkers").click(saveMarkers);
$(".btnResetMap").click(resetMap);
$(".btnCleanMarkers").click(removeAllMarkers);
//build the map
$.ajax({
async: false,
type: "POST",
url: "SetMarkers.aspx/findMapParameters",
data: "{idMapa: '" + idMap + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: response
});
var mapDiv = document.getElementById('map-canvas');
map = new google.maps.Map(mapDiv, {
center: new google.maps.LatLng(lat, lng),
zoom: zoom,
mapTypeId: google.maps.MapTypeId.ROADMAP,
disableDefaultUI: true,
disableDoubleClickZoom: true
});
google.maps.event.addListenerOnce(map, 'idle', loadMarkers);
google.maps.event.addListener(map, 'dblclick', addMarkers);
}
答案 0 :(得分:2)
mi问题很简单我收到错误的中心,只有我需要做的事情是通过center[1]
通过center[0]
切换lat,并添加与标记关联的缩放属性zoom