Android: get location updates without interfering with osmdroid.MyLocationOverlay

StackOverflow https://stackoverflow.com/questions/20825077

  •  22-09-2022
  •  | 
  •  

سؤال

Android / location:

I would like to receive location updates every 5 seconds.

Should I call the method:

locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,5000, 0, gpsLocListener)?

It is important for me NOT to interfere with the osmdroid MyLocationManager functionality. Or should I use the MyLocationOverlay.onLocationChanged(), e.g. by inheritance of the MyLocationOverlay class.

If so, how often will it be called?

هل كانت مفيدة؟

المحلول

There should be no problem having multiple listeners on the location manager. Each one will get events separately. In fact, if you wanted you could use a new instance of osmdroid's GpsMyLocationProvider to feed you location updates. Call mGpsMyLocationProvider.startLocationProvider(myLocationConsumer) where myLocationConsumer is an instance of IMyLocationConsumer that receives and handles gps updates as you wish. You can call mGpsMyLocationProvider.setLocationUpdateMinTime() to adjust how often you get updates.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top