Pregunta

So I have the following code:

LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);

LocationListener locationListener = new LocationListener() {

  public void onLocationChanged(Location location) {

    makeUseOfNewLocation(location);
  }

  public void onStatusChanged(String provider, int status, Bundle extras) {}

  public void onProviderEnabled(String provider) {}

  public void onProviderDisabled(String provider) {}
};
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, Integer.MAX_VALUE, 1 locationListener);

From http://developer.android.com/guide/topics/location/strategies.html

But the thing is I want to call makeUseOfNewLocation(location); every 1 meter, I walked through my house(with my internet from the provider ON) and still did not manage to get in makeUseOfNewLocation(Location location).

I am using Integer.MAX_VALUE because the time for request does not matter.

How can I fix the problem? Can you help me?

¿Fue útil?

Solución

The second parameter where you have Integer.MAX_VALUE is where you put in the distance.

See the documentation for LocationManager at http://developer.android.com/reference/android/location/LocationManager.html#requestLocationUpdates(long, float, android.location.Criteria, android.app.PendingIntent)

1f instead of Integer.MAX_VALUE should do it, provided everything else is OK.

Edit Actually, check the documentation. Looks like your call there is more than a bit inaccurate (for what you are trying to do -- looks like wrong version of the function).

Edit #2 Based on your reply, you have set infinity as the minimum time between updates. Try 0f. Also, for the minDistance, try 1f instead of 1 to ensure it is a float.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top