AndroidLocationStarterKit
AndroidLocationStarterKit copied to clipboard
Count number of good locations before showing Start button.
This is a demo to show how we can count good locations before allowing user to track their locations. Here is the step
1.
Add a varibale goodGpsCount
to count the number of initial good locations.
https://github.com/mizutori/AndroidLocationStarterKit/pull/6/files#diff-93d98e0953cbfe5d527fa9991537cb545dd5dbe6d4b4dfc65992105478fc2077R59
2.
In onLocationUpdate, after filtering the new location, if it passes the filter, count up goodGpsCount
.
If goodGpsCount
becomes more than or equal to 3, send broadcast to MainActivity.
https://github.com/mizutori/AndroidLocationStarterKit/pull/6/files#diff-93d98e0953cbfe5d527fa9991537cb545dd5dbe6d4b4dfc65992105478fc2077R286
3.
In MainActivity, make the startButton
invisible in the beginning.
https://github.com/mizutori/AndroidLocationStarterKit/pull/6/files#diff-40c5403e3f39c3d55b4e8d6447d31e6378231d346d6d955214bcc10bc9c3aa31R198
4.
When receiving the broadcast of goodGpsCount, make startButton
visible.
https://github.com/mizutori/AndroidLocationStarterKit/pull/6/files#diff-40c5403e3f39c3d55b4e8d6447d31e6378231d346d6d955214bcc10bc9c3aa31R147
Other Note
- I changed the function
filterAndAddLocation
tofilterLocation
to return null (if location doesn't pass the filter) or location (if the location passes the filter). This is because I want to use this function even before the user pressesstartButton
. - I removed Kalman filter to demonstrate this idea with maximum simplicity.