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: 524

posted

0

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: 524

posted

0

And then I use Math.round(distance); to convert it to long.

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: 524

posted

0

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?

"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

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: 524

posted

0

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

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.

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.

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.

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.