使用 gmaps4rails 获取标记信息窗口
Get marker infowindow using 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
而不是 marker.infowindow.open
使用 marker.infowindow.render_to_string
参考这个 link (https://github.com/apneadiving/Google-Maps-for-Rails/wiki/Controller)
我正在使用 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
而不是 marker.infowindow.open
使用 marker.infowindow.render_to_string
参考这个 link (https://github.com/apneadiving/Google-Maps-for-Rails/wiki/Controller)