Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/371.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/google-maps/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 谷歌地图API(使用gmapsjs),setCenter抛出;“未定义”不是一个函数;?_Javascript_Google Maps_Google Maps Api 3 - Fatal编程技术网

Javascript 谷歌地图API(使用gmapsjs),setCenter抛出;“未定义”不是一个函数;?

Javascript 谷歌地图API(使用gmapsjs),setCenter抛出;“未定义”不是一个函数;?,javascript,google-maps,google-maps-api-3,Javascript,Google Maps,Google Maps Api 3,我正在尝试使用设置地图中心。当我调整窗口大小时,我得到: 未捕获类型错误:未定义不是函数 这里是调整大小事件的映射和侦听器: $(function () { var holder = $('#map-property'), lat = 46.534820, lng = 13.024809; var map = new GMaps({ div: '#'+holder.attr('id'), lat: lat,

我正在尝试使用设置地图中心。当我调整窗口大小时,我得到:

未捕获类型错误:未定义不是函数

这里是
调整大小
事件的映射和侦听器:

$(function () {
    var holder = $('#map-property'),
        lat = 46.534820,
        lng = 13.024809;

    var map = new GMaps({
        div: '#'+holder.attr('id'),
        lat: lat,
        lng: lng,
        zoom: 14,
        scrollwheel: false,
        panControl : false,
        streetViewControl: false,
        mapTypeControl: false,
        draggable: true,
        disableDoubleClickZoom: true,
        zoomControlOptions:{
            style:google.maps.ZoomControlStyle.SMALL
        }
    })
    .addMarker({
        lat: 46.534820,
        lng: 13.024809,
        title: 'Da Matteo',
        icon: "/img/gmaps-marker.png"
    });

    $(window).on('resize', function() {
        map.setCenter(lat, lng); // here is the error!
    });
});
a确认
setCenter
功能为:

this.setCenter = function(lat, lng, callback) {
  this.map.panTo(new google.maps.LatLng(lat, lng));

  if (callback) {
    callback();
  }
};

问题是,
map=new Gmaps().addMarker()
返回一个标记对象,而不是一个映射。因此,它没有
setCenter
方法

您可以执行以下操作:

var map = new Gmaps({...})
map.addMarker({...})
然后写下事件