通过Ajax使用gmaps4rails渲染Google地图 [英] Rendering google map using gmaps4rails through Ajax
本文介绍了通过Ajax使用gmaps4rails渲染Google地图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我只想按需渲染地图(以最大程度地减少加载时间),这意味着显示地图"之类的链接应在指定的div中渲染地图.我该怎么办?
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?
推荐答案
只需使用此处描述的'to_gmaps4rails'方法: https://github.com/apneadiving/Google-Maps-for-Rails /wiki/Methods
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) %>
这将仅呈现显示资产所需的js.
This will render only the js necessary to display your assets.
因此,包括gmaps4rails.js和.css(如果需要),以及div以托管地图.
So include gmaps4rails.js and .css (if necessary), and the div to host the map.
这篇关于通过Ajax使用gmaps4rails渲染Google地图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文