The distance between two points google maps a is undefined api v3

Update to version v3. The library is declared as follows:

<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false&v=3&libraries=geometry"></script> 

Finding the distance as follows:

 var loc1 = google.maps.LatLng(52.5773139, 1.3712427); var loc2 = google.maps.LatLng(52.4788314, 1.7577444); alert(google.maps.geometry.spherical.computeDistanceBetween (loc1, loc2)); 

Firebug returns this:

 TypeError: a is undefined 

Assuming this is an error, because lat and lon should be passed as objects, so after some searches I tried this:

 var loc1 = google.maps.LatLng({'position' :52.5773139, 1.3712427}); var loc2 = google.maps.LatLng({'position' :52.4788314, 1.7577444}); 

Still getting the same error that I am doing wrong?

+4
source share
1 answer

You must use the new keyword to create the LatLng object.

 var loc1 = new google.maps.LatLng(52.5773139, 1.3712427); var loc2 = new google.maps.LatLng(52.4788314, 1.7577444); 
+4
source

Source: https://habr.com/ru/post/1490534/


All Articles