Jump to content

Error Google Maps Api


svdb

Recommended Posts

I'm not very familiar with JavaScript. I'm implementing a Google Maps API into my website and using the exact code google provides in the developers guide. But it gives an error, this is the code

<script type="text/javascript"    src="http://maps.googleapis.com/maps/api/js?key=mykey_ididchangethis&sensor=false"></script><script type="text/javascript">	  function initialize() {	    var frontmap = {		  zoom: 8,		  center: new google.maps.LatLng(52.22, 4.53),		  mapTypeId: google.maps.MapTypeId.ROADMAP	    };	    var map = new google.maps.Map(document.getElementById('map_canvas'),		    frontmap);	  }	  function loadScript() {	    var script = document.createElement('script');	    script.type = 'text/javascript';	    script.src = 'https://maps.googleapis.com/maps/api/js?sensor=false&' +		    'callback=initialize';	    document.body.appendChild(script);	  }	  window.onload = loadScript;</script>

It says: missing ; before statement (on column 2) So any ideas? Thanks

Link to comment
Share on other sites

the best place to look for javascript errors is in the error/javascript console. I can't see anything immediately that could be a problem (still don't know the exact line number), but a possible an issue is that your api_key needs to URI encoded when included as part of the pages markup.

Link to comment
Share on other sites

Look for the error console. Open it in Firefox and press Control+Shift+J. I don't know the shortcut for other browsers, but you need to search for the "error console" or "javascript console" in your browser.

Link to comment
Share on other sites

If I take this:

<html><head></head><body><script type="text/javascript"	src="http://maps.googleapis.com/maps/api/js?key=mykey_ididchangethis&sensor=false"></script><script type="text/javascript">		  function initialize() {			var frontmap = {				  zoom: 8,				  center: new google.maps.LatLng(52.22, 4.53),				  mapTypeId: google.maps.MapTypeId.ROADMAP			};			var map = new google.maps.Map(document.getElementById('map_canvas'),					frontmap);		  }		  function loadScript() {			var script = document.createElement('script');			script.type = 'text/javascript';			script.src = 'https://maps.googleapis.com/maps/api/js?sensor=false&' +					'callback=initialize';			document.body.appendChild(script);		  }		  window.onload = loadScript;</script></body></html>

And paste it into a tool like JSlint, it does not find any syntax errors. So I'm not sure what your text editor thinks the problem is, but it's not in that code. There are no syntax errors in that code.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...