使用gmaps4rails获取标记信息

时间:2016-04-05 11:24:47

标签: ruby-on-rails ruby google-maps gmaps4rails

我正在使用Rails 4和gem gmaps4rails。我怎样才能在js中获得marker.infowindow? 这是我的代码:

handler = Gmaps.build('Google');
handler.buildMap({ provider: {scrollwheel: false}, internal: {id: 'event-detail-map'}}, function(){
  markers = handler.addMarkers([
      {
          "lat": "<%= @event.location.latitude %>",
          "lng": "<%= @event.location.longitude %>",
          "infowindow": 'Hello!'
      }  
  ]);
  marker = markers[0];
  marker.getServiceObject().addListener('mouseover', function () {
      marker.infowindow.open(marker.serviceObject.map,   marker.serviceObject);
  });

  handler.bounds.extendWith(markers);
  center = {lat: <%= @event.location.latitude %>, lng: <%=@event.location.longitude %>};

  handler.map.centerOn(center);
  handler.getMap().setZoom(12);
});

控制台写信给我:

Uncaught TypeError: Cannot read property 'open' of undefined

1 个答案:

答案 0 :(得分:0)

而不是marker.infowindow.open使用marker.infowindow.render_to_string请参阅此链接(https://github.com/apneadiving/Google-Maps-for-Rails/wiki/Controller