zachstarnes zachstarnes - 4 months ago 22
HTML Question

Google maps api syntax error

I am trying to simply add a google map using the api. I literally copied the code from the tutorial and pasted it to my site. I was then going to edit it after I made sure that it worked. This is in the head of my index page.

<script src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>


I placed the code below in a .js file. I keep getting a syntax error. Here is the code.

function initialize() {
var map_canvas = document.getElementById('map_canvas');
var mapOptions = {
center: new google.maps.LatLng(44.5403, -78.5463),
zoom: 8,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
var map = new google.maps.Map(map_canvas);
}

google.maps.event.addDomListener(window, ‘load’, initialize);


I get the error on the very last line. Can anyone tell me why when all I did was copy it?

Answer

The quote characters you copied are special characters, not the regular ' you need to use in code.

Change it to:

google.maps.event.addDomListener(window, 'load', initialize);