我正在使用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
答案 0 :(得分:0)
而不是marker.infowindow.open
使用marker.infowindow.render_to_string
请参阅此链接(https://github.com/apneadiving/Google-Maps-for-Rails/wiki/Controller)