开发者

Start location strategy

I am receiving periodically location updates via GPS, the problem is the time until the first location update occurs - it is just to long. When the user is within a building, this time gets even worser.

Therefore I am looking for some strategies to improve the startup time (at the moment I don't use getLastKnownLocation but I will). I started reading A Deep Dive Into Location to get some ideas and have some thoughts now I would like to discuss with you.

At first the blog post mentioned above goes through each location provider on the device and queries for the getLastKnownLocation, but only considers them when they are not to old and within an allowed accuracy.

Here comes my first question: I would expect to have the network based location immediately available, so I would request a new network based location, then I would get getLastKnownLocation from the GPS-provider and if the last GPS-location is within the circle formed by the point network based location and radius accuracy then I would take t开发者_StackOverflow社区he GPS location, regardless how old it is. What do you think?

After checking the last known location I will start the GPS position tracking and because I only need it every 2 seconds and 10m change, I would use lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 2 * 1000, 10, this);

However I found a pattern (inside the presentation Being Epic: Best Practices for Android Development on slide 95 and 96 that at first he turns on coarse and fine locations (with 0,0 for time and distance changes) and then, when the first event is received, he switches to the really needed update frequency. So, does the first gps-update comes faster when the interval is set to 0?

In opposite to this pattern I would keep the coarse update until the first GPS update is received. What do you think?

Hope to get some interesting answers!

----------------Update----------------

I did some investigations: I turned on GPS and waited to get a fix. Then I turned GPS off and drove 50km (31 miles). Then I used the code from A Deep Dive Into Location to get all the getLastKnownLocation. I tried it twice, first with GPS turned off and second with GPS turned on, but without a fix:

1) with GPS turned off I got

- Provider: network, correct location with accuracy 680m

- Provider: passive (mProvider=network), same location as above, same time as above

- Provider: gps, location null

So I learned that when gps is turned off you get no getLastKnownLocation.

2) with GPS turned on I got

- Provider: network, correct location with accuracy 652m

- Provider: passive (mProvider=network), same location as above, same time as above

- Provider: gps, location as it was 2h earlier with accuracy 12m, time was also 2h earlier

Here I learned that old messages are not invalidated, even it is obvious that they are wrong.

In that case the algorithm works fine, because I moved in the time I turned the GPS off. But what if I enter a house? In that case the 2h old GPS result would be very good, even it is outdated.


At the Google IO 2013 they showed in the session Beyond the Blue Dot: New Features in Android Location a new approach, see the video here.

The engineers at Google tried a lot of different strategies, the result is the "Fused location provider". Its quality is shown at 12:17 in the video.

Ketan Parmar has published a blog post how the fused location provider can be used in an example application.


Start up the location manager with the passive provider first

locationManager.requestLocationUpdates(LocationManager.PASSIVE_PROVIDER, AlarmManager.INTERVAL_FIFTEEN_MINUTES, 75, this);

then once you get a response from that you can switch to your gps hardware.

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜