我正用这个把头撞到墙上。我想在div中显示屏幕上的地图中心坐标。地图有一个kml图层。当我尝试使用 getCentre()来获取lat&我刚收到这个错误:
Object #<xi> has no method 'getCentre'
我正在使用以下代码生成地图,最后使用getCentre():
map = new google.maps.Map(document.getElementById('map_canvas'), {
center: new google.maps.LatLng(58.401712, 14.577025),
zoom: 4,
overviewMapControl: true,
overviewMapControlOptions: {
opened: true,
},
mapTypeId: google.maps.MapTypeId.SATELLITE
});
loadKmlLayer(src, map);
}
function loadKmlLayer(src, map) {
var kmlLayer = new google.maps.KmlLayer(src, {
suppressInfoWindows: true,
preserveViewport: false,
map: map,
});
var coords = map.getCentre();
答案 0 :(得分:1)
方法是getCenter,而不是getCentre。
map = new google.maps.Map(document.getElementById('map_canvas'), {
center: new google.maps.LatLng(58.401712, 14.577025),
zoom: 4,
overviewMapControl: true,
overviewMapControlOptions: {
opened: true,
},
mapTypeId: google.maps.MapTypeId.SATELLITE
});
loadKmlLayer(src, map);
}
function loadKmlLayer(src, map) {
var kmlLayer = new google.maps.KmlLayer(src, {
suppressInfoWindows: true,
preserveViewport: false,
map: map,
});
var coords = map.getCenter();