Wednesday, June 5, 2024
142
rated 0 times [  148] [ 6]  / answers: 1 / hits: 18447  / 12 Years ago, wed, april 18, 2012, 12:00:00

I'm trying to find the location between two points using google maps. Here is the code that I'm working with:



function initialize() {
var myOptions = {
center: new google.maps.LatLng(36.8813329,-103.6975488),
zoom: 4,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById(map-canvas), myOptions);

var impactCoordinates = [
new google.maps.LatLng(37.772323, -122.214897),
new google.maps.LatLng(34.1633766,-81.6487862),
];
var ImpactPath = new google.maps.Polyline({
path: impactCoordinates,
strokeColor: #FF0000,
strokeOpacity: 1.0,
strokeWeight: 2
});

ImpactPath.setMap(map);

var loc1 = new google.maps.LatLng(37.772323, -122.214897);
var loc2 = new google.maps.LatLng(34.1633766,-81.6487862);

alert(google.maps.geometry.spherical.computeDistanceBetween(loc1, loc2));
}


This is the error I get from the console:




Uncaught TypeError: Cannot read property 'spherical' of undefined



More From » google-maps-api-3

 Answers
25

If you haven't done so, explicitly add the geometry library in your <script> tag
src=http://maps.googleapis.com/maps/api/js?libraries=geometry&sensor=false>


[#86166] Tuesday, April 17, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
savanar

Total Points: 237
Total Questions: 105
Total Answers: 99

Location: Wales
Member since Mon, May 17, 2021
3 Years ago
;