Petar
Petar

Reputation: 2283

Android gps how to skip distance?

I am working on a GPS-enabled application and I need to record a point each N meters. However, I can't see how I can use onLocationChanged() method in the LocationListener or any other method/class. The onLocationChanged() method gives a point each second, and I need to store each N-meter point.

I believe that this has a simple solution, but since I am beginner in Android, cant find it.

Any help will be much appreciated.

Upvotes: 0

Views: 240

Answers (3)

Venus
Venus

Reputation: 219

it is working perfectly myManager = ((LocationManager) ApplicationController.getAppContext().getSystemService( Context.LOCATION_SERVICE )); myManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,1 * 1000, 0.00001f, this);

mintime =1000ms always it is calling ....

Upvotes: 0

EboMike
EboMike

Reputation: 77762

In onLocationChanged, compare the location you get with the last one you stored. If it's less than n meters, discard it. If not, store it. Rinse. Repeat.

EDIT: Wait, even easier - doesn't requestLocationUpdates have a minDistance parameter? See here: http://developer.android.com/reference/android/location/LocationManager.html#requestLocationUpdates

Upvotes: 1

cambraca
cambraca

Reputation: 27827

requestLocationUpdates has a minDistance parameter, that if I recall correctly does what you want. I haven't been able to test this on a real phone though, so I don't know how accurate it is.

Upvotes: 1

Related Questions