Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


  Search this Thread
Old 09-17-2012, 02:46 PM   #1
Senior Member
Registered: Apr 2003
Location: Costa Rica
Distribution: Kubuntu, Debian, Knoppix
Posts: 2,045
Blog Entries: 1

Rep: Reputation: 83
java - jscience: how can I calculate the distance between two LatLong?


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.
Old 09-17-2012, 09:11 PM   #2
LQ Newbie
Registered: Aug 2003
Posts: 25

Rep: Reputation: 5
I googled and clicked on the first link.

Seems like the "Haversine" formula is an easy solution.
The website even has a sample written in JavaScript.
Old 09-18-2012, 03:47 AM   #3
LQ Newbie
Registered: Apr 2006
Posts: 3

Rep: Reputation: 0
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.


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

Old 09-18-2012, 04:49 PM   #4
John VV
LQ Muse
Registered: Aug 2005
Posts: 15,345

Rep: Reputation: Disabled
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


distance, gps, java, jscience

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to calculate network bandwidth using java code? SarahRashad Linux - Newbie 1 01-10-2012 12:18 PM
Calculate e^x in Java ckoniecny Programming 6 07-25-2007 10:28 AM
Extending webcam distance RVDowning Mandriva 6 08-31-2006 07:46 AM
administrative distance abirami Linux - Networking 5 09-23-2004 07:02 AM

All times are GMT -5. The time now is 04:27 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration