Thursday, 30 March 2017

Android GMaps Current Location Using Fused Location Api

This is one of my best codes, to get user's current location using Googles Fused Location Api, coz it's accurate and it's faster in terms of acquiring location.
For this tutorial, the codes should ran in any device, even above api >21, due to the permission checks that i have implemented.

*Click view raw to view a formatted version of the code*

Project Structure: 

Step 1: Create New Project

- Go to start 'start a new project' from the welcome screen > Name it 'Android Fused Location' > Choose 'Google maps activity' *This is the main point* and finish to create the project.

Step 2: Api Key

- After gradle has synced successfully, android studio will open google_maps_api.xml by default. in this xml file, we are required to get our api key from google console and replace it where there is this
phrase "YOUR_KEY_HERE"

Step 3: Coding

i) We first have to add necessary permisions in the AndroidManifest.xml file.

ii)Add necessary libraries in the build.gradle (Module:app)

iii), this class helps us to check if gps and internet are available.

iiv), we add all the logic here, starting by checking if google play service is installed or updated, then we check for the permissions, if device is running android version >21, then we load the map and draw the current location.

Step 4: Running The App