我使用gmaps4rails。我在rails中实例映射它可以工作,但是当我通过atrribute draggable时:地图不起作用。这是我的代码。
handler = Gmaps.build('Google');
handler.buildMap({ provider: {maxZoom: 5}, internal: {id: 'map'}}, function(){
markers = handler.addMarkers([
{
"lat": 22,
"lng": 22,
"picture": {
"width": 32,
"height": 16
},
"infowindow": "hello!",
},
{
"draggable": true
}
]
);
handler.bounds.extendWith(markers);
handler.fitMapToBounds();
handler.map.centerOn({ lat: 22, lng: 22 })
});
答案 0 :(得分:0)
我相信如果你将一些代码移动到控制器(根据Gmaps4Rails指南),你可能会有更好的运气。例如,试试这样:
def index
@geolocations = [{:lat => 22, :lng => 22}]
@hash = Gmaps4rails.build_markers(@geolocations) do |geolocation, marker|
marker.lat geolocation[:lat]
marker.lng geolocation[:lng]
marker.infowindow ("hello!")
marker.picture({"width" => 32, "height" => 16})
end
end
然后是JS:
var mapOptions = {};
var handler = Gmaps.build('Google');
handler.buildMap({ provider: {maxZoom: 5}, internal: {id: 'map'}}, function(){
var markers = handler.addMarkers(<%= raw @hash.to_json %>, {draggable: true});
handler.bounds.extendWith(markers);
handler.map.centerOn([22, 22]);
handler.fitMapToBounds();
});
有关使用处理程序的更多信息:https://github.com/apneadiving/Google-Maps-for-Rails/wiki/Js-Methods