gmaps4rails on jQueryMobile don't work

社会主义新天地 提交于 2019-12-06 16:39:02
  • You need to include the googlemaps javascript files in your layout:
<script type="text/javascript" src="http://maps.google.com/maps/api/js?v=3.5&sensor=false&amp;libraries=geometry"></script>
<script type="text/javascript" src="http://google-maps-utility-library-v3.googlecode.com/svn/tags/infobox/1.1.5/src/infobox.js"></script>
<script type="text/javascript" src="http://google-maps-utility-library-v3.googlecode.com/svn/tags/markerclustererplus/2.0.1/src/markerclusterer.js"></script>
<script type="text/javascript" src="http://google-maps-utility-library-v3.googlecode.com/svn/trunk/richmarker/src/richmarker-compiled.js"></script>
  • the map is created thanks to a window.onload callback. Since the page is already loaded, it fails. So you have to add a jquery mobile callback in your application.js:

$('#gmaps').live('pageshow',function(event){

  Gmaps.loadMaps(); 

});

  • If you want this to work, you have to set an id to the page containing the google map:
<div class="page" data-role="page" id="gmaps">
  • Last, you must prevent double loading of scripts, so change your call to the gmaps4rails helper:

<%= gmaps4rails(@json, false, false) %>

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!