开发者

Rails don't load google maps javascript

I was trying to load a simple google map in my rails application.

The problem is that the web page show only an empty web page.

Here is my index.html.erb

<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript" src="http://www.google.com/jsapi"></script>

<%= javascript_include_tag 'testmap.js' %>


<body onload="initialize(); ">

<div id="map_canvas"></div>

Thi开发者_运维技巧s is my testmap.js which is in "public/javascripts":

var map;
function initialize() {

    var chicago = new google.maps.LatLng(41.850033, -87.6500523);

    map = new google.maps.Map(document.getElementById('map_canvas'), {
      center: chicago,
      zoom: 11,
      mapTypeId: 'roadmap'
    });
  }

The page displayed is completely empty, except for the code loaded from application.html.erb

I hope that you can help me.

Thank you


Use something like Firebug for Firefox in order to see if your JS files are loaded or not.

Maybe something like $(document).ready(function() {} is necessary (You have to wait that your content is loaded before executing your JS).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜