svdb Posted April 20, 2012 Share Posted April 20, 2012 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 More sharing options...
Ingolme Posted April 20, 2012 Share Posted April 20, 2012 Where does it say that. Did it give you a line number? Link to comment Share on other sites More sharing options...
svdb Posted April 20, 2012 Author Share Posted April 20, 2012 I made some screenshots Link to comment Share on other sites More sharing options...
thescientist Posted April 20, 2012 Share Posted April 20, 2012 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 More sharing options...
Ingolme Posted April 20, 2012 Share Posted April 20, 2012 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 More sharing options...
svdb Posted April 20, 2012 Author Share Posted April 20, 2012 Oké, I did as you said in Firefox. It says: missing ; before statement Line: 5, Column: 8 That would be this line: <script type="text/javascript"> Seems error free to me... Link to comment Share on other sites More sharing options...
justsomeguy Posted April 20, 2012 Share Posted April 20, 2012 It sounds like an error in the external file, not the code you posted. Link to comment Share on other sites More sharing options...
svdb Posted April 21, 2012 Author Share Posted April 21, 2012 It sounds like an error in the external file, not the code you posted. But, when this is true, why does my text editor give the same error? Link to comment Share on other sites More sharing options...
Ingolme Posted April 21, 2012 Share Posted April 21, 2012 Did the Firefox error console give you a filename? It should. Link to comment Share on other sites More sharing options...
justsomeguy Posted April 23, 2012 Share Posted April 23, 2012 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.