开发者

LocationManager best implementation?

开发者 https://www.devze.com 2023-02-13 07:27 出处:网络
Is it advisable to implement both LocationManager.NETWORK_PROVIDER and LocationManager.GPS_PROVIDER with the differenct listener and then unregister the listeners locationManager.removeUpdates(locatio

Is it advisable to implement both LocationManager.NETWORK_PROVIDER and LocationManager.GPS_PROVIDER with the differenct listener and then unregister the listeners locationManager.removeUpdates(locationListener) ?

Because GPS_PROVIDER takes lot of time to return the values and sometimes doesn't even gives a call back?

Also, we can have a locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); in handler with a postDelayed to avoid a deadlock in case ther开发者_Python百科e aren't any callbacks?

Any help by anyone?

Thanks in advance!!!

BR, J


Hm afaik locationManager.getLastKnownLocation returns instantly, so you should not see any deadlocks?

If you really need to manage your own LocationListeners, it is advisable to first register a Network-One and a two GPS-ones. Use the network-Listener to receive a first location (rough). Configure one GPS-Location-listener to receive all GPS-Updates. Once the location is accurate neough, switch to a managed GPS-Location-Listener, that only receives updates every x seconds and x meters diff. See http://developer.android.com/guide/topics/location/obtaining-user-location.html for more examples.

If you want to display the location on a map, try MyLocationOverlay. It does all that for you.


Ideally this question wont be valid anymore, since Google finally released newer version of location listeners which would take care of this more effectively. Link for the same below: http://developer.android.com/google/play-services/location.html

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号