getCentre()不使用KML图层谷歌地图

时间:2013-10-15 17:35:31

标签: jquery google-maps

我正用这个把头撞到墙上。我想在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();

1 个答案:

答案 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();