Google maps gmaps4rails方法-Gmaps.map.centerMapOnUser()和Gmaps.map.markers.length

Google maps gmaps4rails方法-Gmaps.map.centerMapOnUser()和Gmaps.map.markers.length,google-maps,google-maps-api-3,gmaps4rails,Google Maps,Google Maps Api 3,Gmaps4rails,这里有两个问题,但它们是相关的。是否有办法使centerMapOnUser()操作顺畅?我有一个标记,表示我的位置,它是可拖动的 // watch for marker movement, and update location accordingly function updateUserLocation(latLng) { var revGeo = new google.maps.Geocoder(); revGeo.geocode({'latLng': latLng}, funct

这里有两个问题,但它们是相关的。是否有办法使
centerMapOnUser()
操作顺畅?我有一个标记,表示我的位置,它是可拖动的

// watch for marker movement, and update location accordingly
function updateUserLocation(latLng) {
  var revGeo = new google.maps.Geocoder();
  revGeo.geocode({'latLng': latLng}, function(results, status) {
    if (status == google.maps.GeocoderStatus.OK) {
      if (results[1]) {
        $('#loc').html(results[1].formatted_address); 
      }
    } else {
      alert("Geocoder failed due to: " + status);
    }
  });
  Gmaps.map.userLocation = latLng;
  Gmaps.map.centerMapOnUser();
  lat = latLng.lat();
  lng = latLng.lng();
}
这是非常突然的,而且几乎让人迷失方向。我想知道是否有人知道一种方法可以使它平稳过渡

附带问题。有时地图显示1个标记,有时显示26(A-Z)。如果仅为1,则缩放级别设置为最大I禁用
auto_zoom
,并添加此功能:

function zoom() {
  if (Gmaps.map.markers.length == 1) {
    //only one marker, choose the zoom level you expect
    Gmaps.map.serviceObject.setZoom(16);
  }
  else{
    //more than one marker, let's auto_zoom
    Gmaps.map.map_options.auto_zoom = true;
    Gmaps.map.adjustMapToBounds();
  }
}

检查控制台,
Gmaps.map.markers
始终返回0,无论是0、1还是多个标记。不过,标记最初是添加的,后来甚至通过
replaceMarkers()
函数添加的,所以一切似乎都配置正确。

更改了
@serviceObject.setCenter(@userLocation)中gmaps4rails.googlemaps.js.coffee中
centerMapOnUser()函数的默认行为
@serviceObject.panTo(@userLocation)
了解第一个问题。另一个仍然在逃避我。