1
I’m trying to calculate the distance between these two points but I’m not getting it! I’d like to find out what the problem is.
On the console, gives error a 404:
distancia.html:14 Uncaught ReferenceError: google is not defined at distancia.html:14 (anonymous) @ distancia.html:14
That’s that line here:
var nyc = new google.maps.LatLng(40.715, -74.002);
Here’s the whole code:
<!DOCTYPE html>
<html>
<head>
<title>TODO supply a title</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<button onclick="myFunction()">Try it</button>
<script>
var nyc = new google.maps.LatLng(40.715, -74.002);
var london = new google.maps.LatLng(51.506, -0.119);
var distance = google.maps.geometry.spherical.computeDistanceBetween(nyc, london);
function myFunction() {
alert(distance);
}
</script>
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyD9A0ThwdhnBC2wLskwCmpWV5aFP1A05pU&libraries=geometry"
async defer></script>
</body>
</html>
@Tmc See this: https://pt.meta.stackoverflow.com/q/6300/132 - This is one of the reasons I rejected this: https://answall.com/review/suggested-edits/129525
– Victor Stafusa