Share your knowledge at the LQ Wiki.
 Home Forums HCL Reviews Tutorials Articles Register Search Today's Posts Mark Forums Read
 LinuxQuestions.org java - jscience: how can I calculate the distance between two LatLong?
 Programming This forum is for all programming questions. The question does not have to be directly related to Linux and any language is fair game.

Notices

 09-17-2012, 02:46 PM #1 eantoranz Senior Member   Registered: Apr 2003 Location: Costa Rica Distribution: Kubuntu, Debian, Knoppix Posts: 2,064 Blog Entries: 1 Rep: java - jscience: how can I calculate the distance between two LatLong? Hi! I need to calculate the distance (meters, kmts, whatever) between two Latitude/Longitude positions? I found jscience which I guess is able to do it but I don't know the API. Could anybody point me to one example? Last edited by eantoranz; 09-17-2012 at 02:47 PM.
 09-17-2012, 09:11 PM #2 abarclay LQ Newbie   Registered: Aug 2003 Posts: 26 Rep: I googled and clicked on the first link. http://www.movable-type.co.uk/scripts/latlong.html Seems like the "Haversine" formula is an easy solution. The website even has a sample written in JavaScript.
 09-18-2012, 03:47 AM #3 ajtucker LQ Newbie   Registered: Apr 2006 Posts: 3 Rep: A quick look at the jscience API doesn't reveal any method of calculating distance, but it may be buried in there somewhere. I've used the jcoord library before now which has a nice and simple interface, e.g. Code: ```import uk.me.jstott.jcoord.LatLng; LatLng centre = new LatLng(lat, lon); LatLon somePoi = new LatLon(poiLat, poiLon); Double dist = centre.distance(somePoi);``` Note however, that it looks as though the project website has been hacked, so be careful! I can send along my copy of the jar if it helps. A more complete set of libraries comes from the GeoTools project, where they use a library by the name of JTS. See http://docs.geotools.org/latest/user...y/api/jts.html for an example of calculating distance with these libraries. In the end, it may be just as easy to implement the Haversine formula yourself, depending on how accurate you need things to be, the coordinate reference systems being used, where on the Earth you want it to work, etc. Alex.
09-18-2012, 04:49 PM   #4
John VV
LQ Muse

Registered: Aug 2005
Location: A2 area Mi.
Posts: 17,093

Rep:
Quote:
 I need to calculate the distance (meters, kmts, whatever) between two Latitude/Longitude positions?
paper and pen are still the best

but are you using a GIS program ?

my self i use ISIS3

more seriously

is this on a "perfect" sphere?
or on the Earth's aeroid
or say the Real distance say from new york to Detroit using the Earth's DEM

Last edited by John VV; 09-18-2012 at 05:04 PM. Reason: added

 Tags distance, gps, java, jscience

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is Off HTML code is Off Forum Rules

 Similar Threads Thread Thread Starter Forum Replies Last Post SarahRashad Linux - Newbie 1 01-10-2012 12:18 PM ckoniecny Programming 6 07-25-2007 10:28 AM RVDowning Mandriva 6 08-31-2006 07:46 AM abirami Linux - Networking 5 09-23-2004 07:02 AM

All times are GMT -5. The time now is 08:02 PM.

 Contact Us - Advertising Info - Rules - LQ Merchandise - Donations - Contributing Member - LQ Sitemap -