Reputation: 4941
I am following tutorial "Adding a Google Map to your website"
But for some reason its not working... may be i missed something..
HTML:
<div id="map_canvas"></div>
CSS:
#map_canvas {
width: 500px;
height: 400px;
background-color: #CCC;
}
JS:
$(function () {
function initialize() {
var map_canvas = document.getElementById('map_canvas');
var map_options = {
center: new google.maps.LatLng(44.5403, -78.5463),
zoom: 8,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
var map = new google.maps.Map(map_canvas, map_options)
}
google.maps.event.addDomListener(window, 'load', initialize);
});
Note: In the fiddle resources i have added Google-Api
I just cant figure-out what did i do wrong... html, css & java script all are the same as in the tutorial.. i even added $(function (){
to make sure script loads after document but didn't helped...
Upvotes: 0
Views: 99
Reputation: 2123
The code is all fine.
In fiddle: On the left top side
Below Frameworks and Extension
Select:
No-Wrap in <head>
from the second drop down.
DEMO: http://jsfiddle.net/DVT7B/3/
Upvotes: 1
Reputation: 161334
$(function () {} and google.maps.event.addDomListener(window,'load',...) do the same thing, just call initialize inside the jquery $ function. Adding the background-color to the css also is a problem.
adjusted javascript:
$(function () {
function initialize() {
var map_canvas = document.getElementById('map_canvas');
var map_options = {
center: new google.maps.LatLng(44.5403, -78.5463),
zoom: 8,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
var map = new google.maps.Map(map_canvas, map_options)
}
initialize();
});
adjusted css:
#map_canvas {
width: 500px;
height: 400px;
}
Upvotes: 1