Location & Map


 

  1. Using LocationManager
  2. Location with Address
  3. Google Map

 

1. Using LocationManager
Step 1 : Select File -> New -> Project -> Android Application Project. Fill the forms, create “Blank Activity” and click “Finish” button.
Step 2 : Open res -> layout -> activity_main.xml and add following code :

Step 3 : Open src -> package -> MainActivity.java and add following code :

Step 4 : Create new class, PermissionUtill.java and add following code :

Step 5 : Open AndroidManifest.xml and add following code :

Step 6 : Open build.gradle(Module: app) and add following code :

ScreenShot:

Download SourceCode

 

2. Location with Address
Step 1 : Select File -> New -> Project -> Android Application Project. Fill the forms, create “Blank Activity” and click “Finish” button.
Step 2 : Open res -> layout -> activity_main.xml and add following code :

Step 3 : Open src -> package -> MainActivity.java and add following code :

Step 4 : Open AndroidManifest.xml and add following code :

Step 5 : Open build.gradle(Module: app) and add following code :

ScreenShot:

gps_address

Download SourceCode

 

3. Google Map

Steps to do before:

Registering for Google MAP V2:

  1. Open the Google Cloud Console.
  2. If you haven’t created the API project yet, click CREATE PROJECT. Give the name of the project and click Create.
    Select Project
    mapv2_new_project
  3. Note down the project number. You will use the project number as sender ID in the registration process.
  4. In the sidebar on the left, click APIs and auth. In the displayed list of APIs, turn the Google Map Android API toggle to ON.
    mapv2_api
  5. In the sidebar on the left, click APIs and auth and Credentials.Select Credentials
  6. Click CREATE NEW KEY and select Android Key.
    Creating New Android Key
  7. we need to generate SHA-1 fingerprint using java keytool. Open your terminal and execute the following command to generate SHA-1 fingerprint. Please Note: We need to generate two separate SHA-1 fingerprint i.e one for debug keystore and another one for release keystore. In this tutorial, i’m explaining only on debug keystore and password is ‘android‘ for all debug keystore.
    mapv2_debug_keystore_sha1
  8. On step 6, a popup window asking the SHA1 and package name. Enter your SHA 1 and your android project package name. And note down the API key which required later in our project.
    mapv2_key

Step 1 : Select File -> New -> Project -> Android Application Project. Fill the forms, create “Blank Activity” and click “Finish” button.
Step 2 : Open res -> layout -> activity_main.xml and add following code :

Step 3 : Open src -> package -> MainActivity.java and add following code :

Step 4 : Open res -> menu -> main.xml and add following code :

Step 5 : Open AndroidManifest.xml and add following code :

ScreenShot:

map5 map6 map map2 map3 map4

Download SourceCode