问题
I want to render the map only on demand(to minimize the loading time), means some link like 'Show Map' should render the map in a specified div. what should i do?
回答1:
Simply use the 'to_gmaps4rails' method described here: https://github.com/apneadiving/Google-Maps-for-Rails/wiki/Methods
Basically, do:
<%=raw assets_hash.to_gmaps4rails(true) %>
This will render only the js necessary to display your assets.
So include gmaps4rails.js and .css (if necessary), and the div to host the map.
来源:https://stackoverflow.com/questions/5611113/rendering-google-map-using-gmaps4rails-through-ajax