Friday, May 17, 2024
 Popular · Latest · Hot · Upcoming
131
rated 0 times [  136] [ 5]  / answers: 1 / hits: 37748  / 11 Years ago, tue, december 3, 2013, 12:00:00

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>

More From » html

 Answers
2

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


[#73928] Sunday, December 1, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
mira

Total Points: 460
Total Questions: 108
Total Answers: 99

Location: American Samoa
Member since Fri, Aug 26, 2022
2 Years ago
mira questions
;