Get location in Android using Fused Location Provider Api
How to get location in Android : Fused Location Provider Api
Hi…Today if we see the current application trends then there is huge requirement of tracking or knowing location related activities of user.
Think of the scenario (e.g) :
1.How to display the custom products to user by based on user’s current location
2.Show nearby restaurants ,hospitals.
3.Show the user what’s other people is buying near them in e-commerce application and many more.
And all these uses the users current location to make the magic happen.
So content of post will go like this:
- Configure the code for Fused Location Provider
- Fetch current latitude and longitude
- Refresh interval for updating latitude and longitude
- Mapping the latitude and longitude using Reverse Geocoding to fetch address details like pincode,city and other details.
So today we will see one api provided by Google which helps to fetch user’s latitude and longitude and by reverse Geocoding it binds that latitude and longitude to print city name with pincode.
Fused Location Provider Api
is the latest api released by Google Play Services and thus today in this tutorial we will explore the sample code to detect the location in Android application using Fused Location Provider Api.
Note: Please run the app in real devices and don’t use in emulators,Update your sdk to have the latest Google Play Services.
And also this app requires the Google Play Services installed phone.
Finally what we read earlier in this post below is the video which shares more info about the usage of fused location provider api :
You can watch this video :
1.Simple Api Implementation:
Api implementation is very clear and simple as compared to old Location Api.
Meets wide range of requirements even those app which requires frequent location updates or accurate location updates.
Based on all incoming location requests and available sensors,this api chooses the most efficient way to meet those needs.
Main benefit: We do not have to switch to location settings to on the location or GPS ,instead this api will automatically show us the settings screen if it detects that location is not on.
Google had recently updated the Fused Location Provider api with Fused Location Provider Client to just get the location in very few lines of code and with very less overhead involved. Infact there is one issue related to Google Location fetching which can result into Null Pointer Exception was also solved.
In addition to above repository I am sharing the Fused Location Provider Client which is new addition to already great apis. This new api makes the enhancement in solving one bug in Fused Location Provider api.
But that’s very basic code to fetch the latitude and longitude(SettingsClient Api also included to check if Location Services is enabled or not).
In conclusion we can say that Fused Location Provider Client will be new future and hope this post will guide you in right direction.
Please comment if you like this post and give your suggestions..so we can improve together.
You can visit this link to know more: