aspose file tools*
The moose likes Java in General and the fly likes Calculating distance between two points represented by lat,long upto 15 feet accuracy Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Calculating distance between two points represented by lat,long upto 15 feet accuracy" Watch "Calculating distance between two points represented by lat,long upto 15 feet accuracy" New topic
Author

Calculating distance between two points represented by lat,long upto 15 feet accuracy

Saurabh Pillai
Ranch Hand

Joined: Sep 12, 2008
Posts: 507
I have converted the formula into Java provided here. But accuracy is a problem. We are using GPS coordinates.

Is GPS coordinate good enough input for feet level accuracy? Or I should be looking into something else?

Saurabh Pillai
Ranch Hand

Joined: Sep 12, 2008
Posts: 507
Problem is I am not getting accuracy. The distance that I get using the formula mentioned in above link, is not same as actual distance.

For example, actual 25 feet distance we are getting 7 feet distance. Application could be I want to open door when I am 10 feet away from my door. I am pushing my location to server every second. and server has location of my door. Both in GPS coordinates.
Saurabh Pillai
Ranch Hand

Joined: Sep 12, 2008
Posts: 507




And then I use Math.round(distance); to convert it to long.
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18724
    
  40

Saurabh Pillai wrote:I have converted the formula into Java provided here. But accuracy is a problem. We are using GPS coordinates.

Is GPS coordinate good enough input for feet level accuracy? Or I should be looking into something else?



I believe that most GPS are accurate to about 4 meters -- and even that number is kinda rough.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Saurabh Pillai
Ranch Hand

Joined: Sep 12, 2008
Posts: 507
Do you have any alternative way that I can look for? My target is to find the distance automatically and trigger the event when threshold is reached.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

So is your problem that your GPS coordinates aren't accurate enough, or that your formula is incorrect?

(I find your formula hard to understand with all those Math.toRadians cluttering it up, and I haven't tried to derive it myself from trigonometry, but it looks to me like you're approximating the earth as a sphere, which is not entirely accurate. However I have no idea how much error that would introduce.)
Saurabh Pillai
Ranch Hand

Joined: Sep 12, 2008
Posts: 507
Paul Clapham wrote:So is your problem that your GPS coordinates aren't accurate enough, or that your formula is incorrect?


I don't have any way to isolate the problem. I have been given the requirement calculating the distance from GPS coordinates. I googled it and came across the link provided in my first post and assumed it is correct.
Do you have any other better way to calculate the distance?
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

I don't know about "better" -- but here's the formula I've used in the past to calculate distances from my GPS tracks:



And it's worked pretty well for me. (And yes, I did get it from the internet, but don't ask me where because I've forgotten.)

fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11231
    
  16

What exactly do your specs say? I found this:

"the GPS signal in space will provide a "worst case" pseudorange accuracy of 7.8 meters at a 95% confidence level." It goes on to say that real-world data indicates a good GPS receiver can frequently be accurate to within 3 meters. If you have a base station, you can be accurate to within a few centimeters.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 7653
    
  19

Saurabh Pillai wrote:And then I use Math.round(distance); to convert it to long.

1. You could also save yourself a lot of method calls by simple converting this.latitiude and this.longditude to radians once.

2. I seems to me that you could also encapsulate latitude and longditude into a Position class, and then implement a
public double distance(Position from) { ...
method. Seems much less hassle to me than trying to deal with individual axes. You could then also convert your latitude/longditude values to radians at creation time.


PS: Please DontWriteLongLines. It makes your thread very hard to read.
I've broken yours up this time, but for future reference, please remember:
80 characters max.
(the SSCCE page actually recommends 62)
And that includes string literals AND comments.

Oh, and you're usually better off using spaces for indentation, rather than TABs.

Thanks.

Winston


Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
Saurabh Pillai
Ranch Hand

Joined: Sep 12, 2008
Posts: 507
@Paul Clapham Thank you I will look into it.

@fred rosenberger We are using iPhone GPS. But after some of the discussion here and reading up material, it feels like I am not using right tool for the problem.

@Winston Gutkowski
1. Agree.
2. Why do I need a separate class for this? I am trying to use it more as an utility method.
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 7653
    
  19

Saurabh Pillai wrote:2. Why do I need a separate class for this? I am trying to use it more as an utility method.

Because Java is an Object-Oriented language, and a Position is a lot more than just two double values stuck together. It describes a point on the surface of a sphere (in fact, a very specific sphere: the Earth).

If you want to make a utility out of it, just create a:in your Position class, that returns p1.distance(p2).

And thinking about it, distanceTo(Position) might be a better name for your instance method.

Winston
Joe Areeda
Ranch Hand

Joined: Apr 15, 2011
Posts: 315
    
    2

It seems to me there are a few issues at play here

First is the inherent resolution of GPS with the equipment you have. This depends on a lot of things from the number of satellites being seen and used at the moment and the precision that the receiver sends to your program. If you are trying to use GPS indoors the number of satellites is very limited and a mobile phone may be using cell towers to report your position.

Next I've played with some cheap USB and some handheld aviation grade GPS that use the NMEA protocol and end up sending degrees to 4 or 5 decimal places. That's a precision of about 10 or 1 meters (circumference of the earth/360 degrees/10^4 or 5)

Finally there's distance calculating algorithm.

You can test your algorithm by fixing longitude or latitude and testing small changes in the other then both. Paul's algorithm estimates the radius of the earth at 6371 km, I don't see the constants you're using.

To test the phone's accuracy I would go outside to make sure you're receiving a good gps signal and see what it reports for locations you should be able to see how far you have to move to get a different reading and how consistent it is a fixed locations.

My guess is that if you need accuracy to a foot or 2 indoors, an iPhone is not going to work for you.

Joe


It's not what your program can do, it's what your users do with the program.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38363
    
  23
There is another problem if you are using that GPs in real life: the Earth is not spherical. The simple trigonometrical method assume the Earth is a sphere.
Joe Areeda
Ranch Hand

Joined: Apr 15, 2011
Posts: 315
    
    2

Campbell Ritchie wrote:There is another problem if you are using that GPs in real life: the Earth is not spherical. The simple trigonometrical method assume the Earth is a sphere.


That's true but when calculating distances on the order of a few feet or a few thousand feet it probably won't be a significant source of error.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

In my case the two points I've been calculating the distance between are two points which are no more than one minute of walking distance apart.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38363
    
  23
Agree: if the two points are that close together my errors will cancel each other out.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Calculating distance between two points represented by lat,long upto 15 feet accuracy