Uncaught ReferenceError: google is not defined (index):21 initialize ( Google Maps API )

google-maps, html, javascript

Solution

There was problem in `script` declaration in your code. You missed to close `script` tag for `jquery` and hence google map js wasn't load properly.

Just change below...

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"**[[Problem is here]]**</script>
<script type="text/javascript"
  src="https://maps.googleapis.com/maps/api/js?sensor=false">
  </script>

to

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
<script type="text/javascript"
  src="https://maps.googleapis.com/maps/api/js?sensor=false">
  </script>

and it should work fine.

Here's Demo

Problem

Keep on getting this error in the console "Uncaught ReferenceError: google is not defined". Been doing it for a while now but no luck. Any help greatly appreciated. Thanks in advance ``` <!DOCTYPE html> <html> <head> <meta name="viewport" content="initial-scale=1.0, user-scalable=no" /> <style type="text/css"> html { height: 100% } body { height: 100%; margin: 0; padding: 0 } #map-canvas { height: 100% } </style> <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"</script> <script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?sensor=false"> </script> <script type="text/javascript"> function initialize(location) { console.log(location); var mapOptions = { center: new google.maps.LatLng(location.coords.latitude, location.coords.longitude), zoom: 8 }; var map = new google.maps.Map(document.getElementById("map-canvas"), mapOptions); } $(document).ready(function() { navigator.geolocation.getCurrentPosition(initialize); }); </script> </head> <body> <div id="map-canvas"/> </body> </html> ```

Original source