Location update rate in Google Maps (Android)

霸气de小男生 提交于 2019-12-22 11:37:35

问题


I'm writing a simple GPS based app for location awareness. Whenever GPS is enabled, the app requests location updates and prints latitude and longitude in a TextView. If GPS is disabled, the location provider fall-backs to LocationManager.NETWORK_PROVIDER for triangulating device position relative to neighboring cell-towers. The aim is whenever device movement is detected, it should start populating the TextView with lat/long. When there is no movement, the process should stop. In order to do so, I've implemented the location update rate as:

locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 1, this);

The above line causes very frequent location updates (even when there is no movement, I keep getting lat/long values). I read somewhere that putting minTime=0 is not a good idea (battery drains faster). When I change it to 2 or 3 seconds, the update becomes very slow (even if the device moves more than 50 meters). Changing minDistance doesn't seem to work either! I want to know what settings does Google Maps application use? Power consumption is not a limiting factor for me as I'm developing the app for some network drive test equipment (which gets constant power from vehicle's on-board lead acid battery).


回答1:


The frequency of updates is highly dependent on the hardware. Good gps chips send very frequent updates(Samsung Galaxy S3) while some struggle even to show lat-lan position. The gist here is normalize the the frequency for receiving updates on the basis of distance and time. Use various time and distance configuration and test them and use the most appropriate values. For my project I used following values: //for walking user

locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 5, 10, this);

//for user in a car

locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 2, 50, this);



来源:https://stackoverflow.com/questions/23379691/location-update-rate-in-google-maps-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!