Reputation: 2036
I am comparing two different ways of calculating a distance between two Points.
Haversine formula found on the page: http://www.movable-type.co.uk/scripts/latlong.html
The following functionality of the geotools library:
GeodeticCalculator geodeticCalculator = new GeodeticCalculator();
geodeticCalculator.setStartingGeographicPoint(lng1, lat1);
geodeticCalculator.setDestinationGeographicPoint(lng2, lat2);
double distance = geodeticCalculator.getOrthodromicDistance();
The result for two coordinates in a range of about 100 meter differs by about 3 meters. And for longer distances (some 1000 km) even more (some kilometers). But it is also hard to check which one is more precise since you don't have a reference that you can really trust. (Don't know for example if google maps is that precise)
Any idea?
Upvotes: 2
Views: 1230
Reputation: 5916
I'm no expert, but the docs on the Haversine formula say that it assumes a spherical earth. Whereas the earth is acutally a geoid shape. And so I'd assume the GeodeticCalculator to be more accurate.
If you want more detal better to ask in the GIS stack exchange.
Upvotes: 2
Reputation: 2036
Just to answer my own question after some more research:
Geotools library is more precise here, since it uses the WGS84 Model by default if instantiated with an empty constructor.
The other formula uses an inacurate spherical model of the earth.
Upvotes: 3