Reputation: 11
I am currently working on a gps project. I have read an xml file, I can print out the longitude and latitude bounds in the form of minLat, maxLat, minLon, maxLon. Way,Relation and Node properties like, id, user, uid, version, visible, changeset and timestamp . I can also print out the tag key and value and the reference. My problem now is that I want to calculate the distance between two points with the use of latitude and longitude, it is unclear to me on how do it and which of the properties that I printed out to console I really need to do it. So please I need some help!
Upvotes: 1
Views: 939
Reputation: 7575
Calculate distance in meters when you know longitude and latitude in java
This one was marked as answered, and there is an example function.
Upvotes: 0
Reputation: 2346
You need to calculate this using the Haversine formula. Here is a snippet of a perl script which does exactly this, I'd suggest taking a look at it for some better explanation: http://jan.ucc.nau.edu/~cvm/latlon_formula.html
And here is a deeper explanation of the problem: http://www.movable-type.co.uk/scripts/latlong.html
Haversine formula:
a = sin²(Δlat/2) + cos(lat1).cos(lat2).sin²(Δlong/2)
c = 2.atan2(√a, √(1−a))
d = R.c
where R is earth’s radius (mean radius = 6,371km); note that angles need to be in radians to pass to trig functions!
(source is the link above)
Upvotes: 1