I have a rails 3.1 application with this simple code in the home page (rhtml file),
- If I run the same code in a html file it works.
- If I run this in my rails app it doesn't and I do not get any kind of errors using firebug.
Also: I have jquery-rails gem. What could be the problem?
<script ty开发者_StackOverflowpe="text/javascript"
src="http://maps.googleapis.com/maps/api/js?sensor=false">
</script>
<script>
jQuery(document).ready(function() {
init();
});
</script>
<script type="text/javascript">
function init() {
var latlng = new google.maps.LatLng(-34.397, 150.644);
var myOptions = {
zoom: 8,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
}
</script>
then I have my div:
<div id="home">
<div style="width:100%;height:400px" id="map_canvas"></div>
</div>
with this css:
#home #map_canvas {
width: 100%;
height: 400px;
position: relative;
left: 0px;
}
Sounds like some other JS and/or CSS that's conflicting.
PS: not sure why you're specifing the style width and height both inline and in a CSS declaration. Only need one of them, although no harm in duplicating.
精彩评论