I need to get my current location using GPS programmatically. How can i achieve it?
相关问题
- How can I create this custom Bottom Navigation on
- Bottom Navigation View gets Shrink Down
- How to make that the snackbar action button be sho
- Listening to outgoing sms not working android
- How to create Circular view on android wear?
相关文章
- android开发 怎么把图片放入drawable的文件夹下
- android上如何获取/storage/emulated/下的文件列表
- androidStudio有个箭头不认识
- SQLite不能创建表
- Windows - Android SDK manager not listing any plat
- Animate Recycler View grid when number of columns
- Why is the app closing suddenly without showing an
- Android OverlayItem.setMarker(): Change the marker
Simplest you can find
Since I didn't like some of the code in the other answers, here's my simple solution. This solution is meant to be usable in an Activity or Service to track the location. It makes sure that it never returns data that's too stale unless you explicitly request stale data. It can be run in either a callback mode to get updates as we receive them, or in poll mode to poll for the most recent info.
Generic LocationTracker interface. Allows us to have multiple types of location trackers and plug the appropriate one in easily:
ProviderLocationTracker- this class will track the location for either GPS or NETWORK.
The is the FallbackLocationTracker, which will track by both GPS and NETWORK, and use whatever location is more accurate.
Since both implement the LocationTracker interface, you can easily change your mind about which one to use. To run the class in poll mode, just call start(). To run it in update mode, call start(Listener).
Also take a look at my blog post on the code
I have got very accurate location using FusedLocationProviderClient
(Google Play services required)
android.permission.ACCESS_FINE_LOCATION
android.permission.ACCESS_COARSE_LOCATION
'com.google.android.gms:play-services-location:15.0.0'