3

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....

Ethan Brown
  • 26,892
  • 4
  • 80
  • 92
  • Perhaps WA not are considering earths curvature? 1036 km is the distance on a flat surface? – davidkonrad Mar 24 '14 at 05:48
  • I should hope WA is considering distance on a sphere...it's regarded as one of the best data mining engines available, and it claims its geospatial capabilities are robust. Now that I've verified the Google Maps solution against the haversine result, I've contacted WA, because if WA is wrong...well, they'll want to know about it. And if I'm using it wrong, I want to know how. – Ethan Brown Mar 24 '14 at 05:50
  • Hm, I don't think it's as simple as WA making the rookie mistake of calculating the cartesian distance. If you take 1°~=111km, the cartesian distance between London and Prague is 1591 km, which is STILL closer to the Google Maps/haversine answer than the WA answer. – Ethan Brown Mar 24 '14 at 05:54
  • 1
    It is a good question indeed. After second thoughts the difference is way to much to have something to do with curvature. Try click "directions" in WA, it shows anything but a crow flies path, but still only 1271 km. Way over my skills, but I would really like to see an answer om that. – davidkonrad Mar 24 '14 at 05:55
  • 1
    Yeah, the "directions" area isn't what worries me...and it does show a straight line on a cartesian projection. I have used WA in the past to verify geospatial applications, and its straight-line distances have agreed with Google/Bing/haversine, so this is new behavior...I think WA has crapped its pants :( – Ethan Brown Mar 24 '14 at 05:57

1 Answers1

3

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!

MrUpsidown
  • 21,592
  • 15
  • 77
  • 131
  • Oh my lord. I knew it was something stupid. Crazy stupid. Thanks, @MrUpisdown. – Ethan Brown Mar 24 '14 at 17:33
  • 2
    What kills me is that the name of the constructor (`LatLng`) *tells* you what order to put the arguments in. I'm going to blame it on the cold I've got...it's scrambled my brains, apparently. – Ethan Brown Mar 24 '14 at 17:38
  • @EthanBrown, been there, in the KML / FusionTablesLayers it is also opposit in various functions. Very confusing. But who would have thinked of that :) – davidkonrad Mar 24 '14 at 17:45