LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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


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

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

Rep: Reputation: 6
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.
 
Old 09-18-2012, 03:47 AM   #3
ajtucker
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.

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.
 
Old 09-18-2012, 04:49 PM   #4
John VV
LQ Muse
 
Registered: Aug 2005
Location: A2 area Mi.
Posts: 17,627

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


Reply

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



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

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:03 AM.

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