gmaps4rails v2界限和缩放

时间:2013-11-13 23:57:16

标签: ruby-on-rails google-maps-api-3 gmaps4rails gmaps4rails2

Gmaps.store.handler.getMap().zoomTo(10)给了我Uncaught TypeError: Object #<pi> has no method 'zoomTo'

直接在上面,我用一个lat和lng调用Gmaps.store.handler.map.centerOn,并且它正确居中,所以我倾向于相信处理程序是正确的。我用

调用处理程序
Gmaps.store = {} #handler, markers, userPin, eventPin
jQuery ->
  Gmaps.store.handler = Gmaps.build 'Google'    
  Gmaps.store.handler.buildMap { internal: {id: 'map'} }, ->
    Gmaps.store.markers = Gmaps.store.handler.addMarkers( $('#map').data('events'), 
      draggable: false
      flat: false
      animation: google.maps.Animation.DROP
    )

    google.maps.event.addListener Gmaps.store.handler.getMap(), 'click', (event) ->
    addEventMarker event.latLng if $('#createEventWindow').is(':visible')

另外,在调用Gmaps.store.handler.bounds时,我得到180和1.我是否也不能在界限上调用.getNorthEast()?控制台告诉我没有这样的功能。这是野兽的照片...

map showing San Diego, bounds are botched

更新

updateSearchLocation = ->
  if $('#collapseOne input#location').val()
    geocoder = new google.maps.Geocoder()
    address = $('#collapseOne input#location').val()
    geocoder.geocode address: address, (results, status) ->
      if status is google.maps.GeocoderStatus.OK
        latLng = results[0].geometry.location
        Gmaps.store.handler.map.centerOn
          lat: latLng.lat()
          lng: latLng.lng()
        Gmaps.store.handler.getMap().setZoom(10)
        console.log Gmaps.store.handler.bounds.getServiceObject().getNorthEast()
        $('#collapseOne input#ne').val Gmaps.store.handler.bounds.getServiceObject().getNorthEast()
        $('#collapseOne input#sw').val Gmaps.store.handler.bounds.getServiceObject().getSouthWest()
      else
        throw status + ' for ' + address

1 个答案:

答案 0 :(得分:2)

设置缩放的google方法为setZoom,所以:

handler.getMap().setZoom(10)

对于边界,自定义对象存储在此处:

handler.bounds

与所有自定义对象(如handler.map)或标记一样,如果您需要访问Google对象,则可以使用getServiceObject()

handler.bounds.getServiceObject()
handler.map.getServiceObject() # same as handler.getMap()
markers[0].getServiceObject()
...