Question

When testing to verify a mapping solution, I came across a discrepancy between the Google Maps API and Wolfram Alpha. Both are sources I trust, so I can only believe I'm doing something wrong, but for the life of me, I can't determine what.

For example, the distance as the crow flies between London (51.5°N, 0.1167°W) and Prague (50.8°N, 14.43°E) yields:

Wolfram Alpha: 1036 km

Google Maps API: 1627 km

That's a pretty significant difference. It's off by similar amounts for distances to other locations. I am not mixing driving distances and line-on-a-sphere distances, nor am I mixing units (everything is in kilometers). For both engines, I am correctly treating longitudes west of the prime meridian as negative, and longitudes east of it positive. For the Google Maps test (see link above), I am using the google.maps.geometry.spherical.computeDistanceBetween method.

UPDATE: I added my own implementation of the haversine formula (jsfiddle), and it agrees with the Google Maps API, so I'm pretty sure that the problem is with Wolfram Alpha. How, though? The input seems pretty unambiguous, as is the output....

Was it helpful?

Solution

Google Maps API gives me a distance of 1034km. You just converted the coordinates wrong.

Your code:

var home = ['London', new google.maps.LatLng(-0.1167, 51.5)];

Correct coordinates for London:

var home = ['London', new google.maps.LatLng(51.5, -0.1167)];

The same applies for the other points in your example. Hope this helps!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top