In the process of upgrading my Route Tracker app, I have encountered problems associated with Google Maps API not loading resulting in the error "Uncaught ReferenceError: google is not defined".
I am including the google maps API URL as follows:
<script src="https://maps.googleapis.com/maps/api/js?key=API_KEY"></script>
and the error is generated by the following statement in Javascript:
coords = new google.maps.LatLng(myLat, myLong);
This app worked very well before but unfortunately no longer as I suspect google introduced significant changes. I have looked at the answers corresponding to the same error message but so far to no avail.
The javascript code snippets are shown below:
function ShowLocation(position)
{
var coords;
var markerOptions = {
map: geolocationClass.map,
position: coords
};
// Fetch coordinates
var myLat = position.coords.latitude;
var myLong = position.coords.longitude;
// Store previous coordinates
coordinatesClass.lat[distanceTimeClass.counter] = myLat;
coordinatesClass.lng[distanceTimeClass.counter] = myLong;
// Google API-ready latitude and longitude
coords = new google.maps.LatLng(myLat, myLong); <--- Error here
.............
.............
}
The function ShowLocation gets called as follows:
function GetLocationUpdate()
{
..............
if (navigator.geolocation)
{
geolocationClass.geoLoc = navigator.geolocation;
geolocationClass.watchID =
geolocationClass.geoLoc.watchPosition(ShowLocation,
ErrorHandler, options);
...........
}
............
}