i am trying to get the users location for my new navigation app. i want to check the users location frequently and it has to be accurate . I use the following code from samp
Absolutely use the new google play location services. They work much better indoors than the old location manager. I have created a sample that uses the new google play location services and works in the background periodically. Check it out:
https://github.com/nickfox/GpsTracker/tree/master/phoneClients/android
When I was working with it, I came across 2 good sources:
The blog post: Android Location Fused Provider. It includes a great complete tutorial on using the FusedLocationProviderApi to get location in Android.
Answers on following Android LocationClient class is deprecated but used in documentation question.
Basically both talk about the similar steps as mentioned in the Google I/O session, link to which is mentioned in one of the answers:
First, to get a GoogleClientApi
instance, like:
GoogleClientApi googleApiClient = new GoogleApiClient.Builder(locationActivity)
.addApi(LocationServices.API)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
Then to call .connect()
on it like:
googleApiClient.connect();
Then in the callback onConnected
, get the last location or even can request the location updates as per your need, eg:
LocationServices.FusedLocationApi.getLastLocation(googleApiClient);
If you want request location updates, then can use the requestLocationUpdates call.
Hope it helps.