Closed cassioscabral closed 10 years ago
Your json representation is one thing.
Passing options during the marker creation is another.
There is no more magic in the gem, it makes it much clearer.
Passing options is the subject of this page: https://github.com/apneadiving/Google-Maps-for-Rails/wiki/Js-Methods
If its not clear enough, feel free to edit it.
In your case, if you want to have draggable markers depending on the json, I recommend you do:
_.each(json_array, function(json){
handler.addMarker( json, { draggable: json.draggable });
});
My confusion was about the gem, it provides a method to insert any JSON into the Marker Builder, with that, I was hoping that draggable or any other option would work. The page is fine, but would be great if had some examples of options.
I fully understand, would be grateful if you improve the doc
Okay, I'm going to look for more options and I will make a PR.
Done, didn't know the wiki could be edited for anyone.
thanks!
Hey, I came upon the same problem, I was wondering, if we're to put draggable option with other set of options, how would it be like ?
for instance
handler.addMarkers([{lat: 0,lng: 0, picture: {url: "/logo.png", width: 36, height: 36}, infowindow: "hello!", draggable :true //? } ]);
Would it be like that?
What I mean to say is , is there a better way of doing it with pretty more options?
No pass google options as a second argument:
handler.addMarkers([{lat: 0,lng: 0,
picture: {url: "/logo.png",
width: 36,
height: 36},
infowindow: "hello!"
},
{
draggable: true
}
]);
doc here: https://github.com/apneadiving/Google-Maps-for-Rails/wiki/Js-Methods
Thanks!
@psycatham no pb, just answered on stackoverflow too, since I just had a look
Yes, I just had one too. Thanks
One other thing, when I call the markers from the controllers as follows
@hash = Gmaps4rails.build_markers(@locations) do |location, marker| marker.lat pad.latitude marker.lng pad.longitude marker.infowindow pad.address marker.picture { "url" => "/logo.png"} end
The asset pipeline does not seem to trigger the logo.png, any hints?
@psycatham use rails view helpers like asset_path or image_path
Does not seem to do it.
Even when replacing it with an external (on the net) , the icon does not appear on the map but when clicked, i get the infowindow.
Is it something with my app?
@psycatham give it a size. basically follow the doc and/or examples here: http://apneadiving.github.io/
@apneadiving when I use image_path/asset_path, either it does not work or it gives me undefined method for #class..
but when using the external url, and correcting the size, it seems to do the trick.
I appreciate the time, thanks :)
@psycatham please post questions on stackoverflow, issues are meant to be bugs
Already done before coming , Apologies.
Using marker.json({draggable: true}) on the build_markers(in the controller) didn't make the marker draggable which seems to be the right syntax and the logically way to add the option following this code(https://github.com/apneadiving/Google-Maps-for-Rails/blob/master/lib/gmaps4rails/markers_builder.rb#L65).
After one hour trying and no success I found @apneadiving answer(http://stackoverflow.com/questions/20231113/gmaps4rails-v2-0-3-gmaps-map-is-undefined) on SO and using this line(in the view) instead did the work just fine.
Was wondering if I did something wrong, but if I didn't it is something that should be mentioned on the docs how to add draggable options on the markers.