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!
Asked
Active
Viewed 907 times
2 Answers
1
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)

tskulbru
- 2,336
- 1
- 20
- 38
-
should I use the minlat, maxlat, minlon and maxlon to calculate it? – lampardchelsea Jul 01 '11 at 21:47
-
Im a bit unsure as to what they represent, but Im guessing its the rough calculation of your position (you are minimum at minlat and maximum at maxlat), so maybe you need to calculate the differencial (unsure). – tskulbru Jul 02 '11 at 08:09
-
Yes they are the attributes bounds in the xml file.But I also have latitude and longitude from the Node tag, that is why I don't really know which of the latitude and longitude I should use to calculate the weight. – lampardchelsea Jul 02 '11 at 22:14
0
Calculate distance in meters when you know longitude and latitude in java
This one was marked as answered, and there is an example function.

Community
- 1
- 1

Matt R. Wilson
- 7,268
- 5
- 32
- 48
-
@serrghi, should I use the minlat, maxlat, minlon and maxlon to calculate it? – lampardchelsea Jul 01 '11 at 21:46