gmaps4rails: Don't show map by default and load markers with ajax
class UsersController < ApplicationController | |
respond_to :html, :json | |
def index | |
@json = User.all.to_gmaps4rails | |
respond_with @json | |
end | |
end |
<!-- create html + load js files but don't create map itself: will be done after ajax call --> | |
<%= gmaps({:last_map => false}) %> | |
<!-- button to trigger ajax call --> | |
<button type="button" id="ajax">Load Map</button> | |
<script type="text/javascript" charset="utf-8"> | |
$(function() { | |
//hide the empty container | |
$(".map_container").hide(); | |
$("#ajax").click(function(){ | |
$.getJSON('/users', function(json){ | |
$(".map_container").show(); | |
Gmaps.loadMaps(); | |
Gmaps.map.addMarkers(json); | |
}) | |
}) | |
}); | |
</script> |
This comment has been minimized.
This comment has been minimized.
steventen
commented
Apr 16, 2013
OK, I figured out. No worries, @apneadiving Instead of
I can add options this way
In which, I used "[]" to fill the data section |
This comment has been minimized.
This comment has been minimized.
pedroassumpcao
commented
Aug 8, 2013
Is there a way to create the sidebar marker list with plain html? |
This comment has been minimized.
This comment has been minimized.
alexwiththescar
commented
Feb 3, 2015
What changes would i make to this for v2? Cant seem to get it working. Its complaining about Gmaps.loadMaps(); as undefined Function? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This comment has been minimized.
steventen commentedApr 15, 2013
Hi, how can I pass options for markers into addMarkers method?