gps distance

local function sphericalDistanceBetween( point1, point2 )

 

    local dLongitude = point2.longitude - point1.longitude

    local dLatitude = point2.latitude - point1.latitude

 

    local R = 6371  – Earth radius in kilometers

 

    – Localize some math calls

    local sin = math.sin

    local cos = math.cos

    local sqrt = math.sqrt

    local atan2 = math.atan2

 

    local a = ( sin( dLatitude/2 ) )^2 + cos( point1.y ) * cos( point2.y ) * ( sin( dLongitude/2 ) )^2

    local c = 2 * atan2( sqrt( a ), sqrt( 1-a ) )

    local d = R * c

 

    return d * math.pi / 180

end

 

I get distance d but when i check in device then on one place that chance continually so now what can i do?

and this d is i get in meter.

If you want to update d, then each time you get a location event triggered, call the above function and you will get a new distance.

What do you want d to be in besides meters?

Kilometers = d / 1000

Miles = d * 0.000621371

Feet = d * 3.28084

If you want other conversions go to Google and search for “meters to miles” or whatever you’re looking for.

Rob

But why d is chance on one place ??
How that possible ???
And also fluction is very big 100 - 200 meter .
How can I get accurate results??

This is how GPS works. Lets address the large distance issue first.

Location Services uses several things to determine where you are. It will use WiFi hot spots, Cellular towers and GPS…  Each of them have various degrees of accuracy. If you’ve ever watched the map app, it draws a light blue circle around your dot to show you its accuracy. It will get smaller and smaller as you get better information.

For GPS, the most accurate measure, your device has to see at least three satellites to get a GPS fix. If you are indoors, there is a good chance that it’s not getting a good signal. GPS also has intentional errors. You can zoom in on the default map app and watch your blue dot move as your just sitting there.

Try going outside and seeing if your large distance improves. As far as it changing while you sit still, you could keep track of say the last three values and average them out to smooth it out a bit.

Rob

can you explain this calculation??

Kilometers = d / 1000

Miles = d * 0.000621371

Feet = d * 3.28084

  1. If you have variable “d” in meters. If you want to know kilometers then divide d by 1000.

  2. If you have variable “d” in meters and you want to know miles, multiply d by 0.000621371. One meter is 0.000621371 miles.

  3. If you have variable “d” in meters and you want to know the distance if feed, multiply d by 3.28084. There is roughly 3.2 feet in each meter.

Rob

I get distance d but when i check in device then on one place that chance continually so now what can i do?

and this d is i get in meter.

If you want to update d, then each time you get a location event triggered, call the above function and you will get a new distance.

What do you want d to be in besides meters?

Kilometers = d / 1000

Miles = d * 0.000621371

Feet = d * 3.28084

If you want other conversions go to Google and search for “meters to miles” or whatever you’re looking for.

Rob

But why d is chance on one place ??
How that possible ???
And also fluction is very big 100 - 200 meter .
How can I get accurate results??

This is how GPS works. Lets address the large distance issue first.

Location Services uses several things to determine where you are. It will use WiFi hot spots, Cellular towers and GPS…  Each of them have various degrees of accuracy. If you’ve ever watched the map app, it draws a light blue circle around your dot to show you its accuracy. It will get smaller and smaller as you get better information.

For GPS, the most accurate measure, your device has to see at least three satellites to get a GPS fix. If you are indoors, there is a good chance that it’s not getting a good signal. GPS also has intentional errors. You can zoom in on the default map app and watch your blue dot move as your just sitting there.

Try going outside and seeing if your large distance improves. As far as it changing while you sit still, you could keep track of say the last three values and average them out to smooth it out a bit.

Rob

can you explain this calculation??

Kilometers = d / 1000

Miles = d * 0.000621371

Feet = d * 3.28084

  1. If you have variable “d” in meters. If you want to know kilometers then divide d by 1000.

  2. If you have variable “d” in meters and you want to know miles, multiply d by 0.000621371. One meter is 0.000621371 miles.

  3. If you have variable “d” in meters and you want to know the distance if feed, multiply d by 3.28084. There is roughly 3.2 feet in each meter.

Rob