apneadiving / Google-Maps-for-Rails

Enables easy Google map + overlays creation in Ruby apps
https://apneadiving.github.io/
MIT License
2.27k stars 382 forks source link

marker.json draggable didn't work #430

Closed cassioscabral closed 10 years ago

cassioscabral commented 10 years ago

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.

markers = handler.addMarkers(<%= raw @hash.to_json %>, {draggable: true});

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.

apneadiving commented 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.

apneadiving commented 10 years ago

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 });
});
cassioscabral commented 10 years ago

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.

apneadiving commented 10 years ago

I fully understand, would be grateful if you improve the doc

cassioscabral commented 10 years ago

Okay, I'm going to look for more options and I will make a PR.

cassioscabral commented 10 years ago

Done, didn't know the wiki could be edited for anyone.

apneadiving commented 10 years ago

thanks!

ghost commented 10 years ago

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?

apneadiving commented 10 years ago

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

ghost commented 10 years ago

Thanks!

apneadiving commented 10 years ago

@psycatham no pb, just answered on stackoverflow too, since I just had a look

ghost commented 10 years ago

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?

apneadiving commented 10 years ago

@psycatham use rails view helpers like asset_path or image_path

ghost commented 10 years ago

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?

apneadiving commented 10 years ago

@psycatham give it a size. basically follow the doc and/or examples here: http://apneadiving.github.io/

ghost commented 10 years ago

@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 :)

apneadiving commented 10 years ago

@psycatham please post questions on stackoverflow, issues are meant to be bugs

ghost commented 10 years ago

Already done before coming , Apologies.