Close

Integrating Google Maps in Android App

Integrating Google Maps in Android App using Android Studio

 

In this blog post I will explain how you can integrate Google Maps in your Android project. Follow the below steps:

 

1. Add the Google Play services package to Android Studio.

2. Create Android Studio Google Map Project. For Creating Android Studio Project follows these given steps:

  • Follow these steps to create a new app project including a map activity:
  • Start Android Studio.
  • Create a new project as follows:
  • If you see the Welcome to Android Studio dialog, choose Start a new Android Studio project, available under ‘Quick Start’ on the right of the dialog.
  • Otherwise, click File in the Android Studio menu bar, then NewNew Project.
  • Enter your app name, company domain, and project location, as prompted. Then click Next.
  • Select the form factors you need for your app. If you’re not sure what you need, just select Phone and Tablet. Then click Next.
  • Select Google Maps Activity in the ‘Add an activity to Mobile’ dialog. Then click Next.
  • Enter the activity name, layout name and title as prompted. The default values are fine. Then click Finish.

 

Now Android Studio will start gradle and build your project. This may take a few of second to build your project. When the build is finished then Android Studio will opens the google_maps_api.xml and MapsActivity.java files in the Editor.(Activity name can have different name but it will be only what name you are given in setup wizard).

 

3. How to Google Maps API Key: Now your application will require an API key to access the Google Map servers. This key is free and you can use this key in your any of Google map api project. You can get Google Maps API key in following steps.

 

  1. Open the Google Developer Console.
  2. Follow the instructions to create a new project on the console. If you have already created an API project you can select that.
  3. Create an Android API key for your console project. You can create API key by using as given steps:       

           a. Click on Credential, It will list out all your created credential and Create credential option.

           b. Choose Create Credential option, when you click on Create credential it will prompt to select                API key option from given options.
           c. When you click on API key, it will further prompt you for choose appropriate option.
           d. Choose Android key option in given prompt dialog.
           e. As soon as you click on Android key it will ask you the package name of project and sh1 key                of your pc that is created from you keystore file with signed or debug keystore file.
               You can get SH1 key by using given command from command prompt or terminal.
                keytool -list -v -keystore mystore.keystore

       4. Copy the resulting API key, go back to Android Studio, and paste the API key into the <string> element in the xml file.

      Note: For using the service of Google Map into you Android project you must have enabled the Google Map Api from Google API Console page. Your app will not be able to access Google Map until you did not enabled the Google Map API for Android.

 

      5. Now take a look at the Code.

 

  • XML layout file(activity_map) will be look as follows.
       <fragment xmlns:android=”http://schemas.android.com/apk/res/android”
        xmlns:tools=”http://schemas.android.com/tools”
        android:layout_width=”match_parent”
        android:layout_height=”match_parent”
        android:id=”@+id/map”
        tools:context=”.MapsActivity”
        android:name=”com.google.android.gms.maps.SupportMapFragment” 
       />
  • The Map Activity java file(MapsActivity.java) : By default it takes MapsActivity.java file name. It should contain the following code after your package name:
       import android.os.Bundle;
       import android.support.v4.app.FragmentActivity;
       import com.google.android.gms.maps.CameraUpdateFactory;
       import com.google.android.gms.maps.GoogleMap;
       import com.google.android.gms.maps.OnMapReadyCallback;
       import com.google.android.gms.maps.SupportMapFragment;
       import com.google.android.gms.maps.model.LatLng;
       import com.google.android.gms.maps.model.MarkerOptions;

 

public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {

 

private GoogleMap mMap;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}

 

@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;

 

// Add a marker in Sydney, Australia, and move the camera.
LatLng sydney = new LatLng(-34, 151);
mMap.addMarker(new MarkerOptions().position(sydney).title(“Marker in Sydney”));
mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
}
}

 

If in any case your .java file does not contain above code the you can replace your code with above of the  code in Your MapsActivity.java file.

 

       6. Manifest File(permissions needed for your app)

 

Manifest file contains all the information about your app. In manifest file you must have to declared following part of code. Manifest file should contain following permission.

<uses-permission android:name=“android.permission.ACCESS_FINE_LOCATION” /> 

Manifest file should contain information about your google map api key and google play services version in MetaData like as follows: 

<meta-data
android:name=“com.google.android.gms.version”
android:value=“@integer/google_play_services_version” />                               
<meta-data
android:name=“com.google.android.geo.API_KEY”
android:value=“@string/google_maps_key” />

 

       7. Connect an Android device

 

Best way to see your app in action is Run your app in Android device. You can also use Android Emulator as alternate of it. Your android phone should have developer option enabled.

 

        8. Build and Run your app

 

In Android Studio you can run your app by using Run menu option. You can also use play button icon to Run your app. When you play or run your app it will prompt you to select device. You can choose one of the following option:

  • Select your Android phone that you have connected with Computer or
  • You can select Android Emulator radio button and choose available or created virtual Android emulator.
  • Click on Ok, Android Studio will start gradle to build your app and display to corresponding results on a device or in Emulator. It can take couple of minute before open the app. You should able to see corresponding result on Google map with a pin.

 

 Still facing any issue with Google Maps? Or want to be in touch with us? Contact us at  support@triffort.com

 

 

 

Triffort Technologies Pvt Ltd
www.triffort.com

 

 

Posted in Android | Tagged androidgoogle mapsgoogle studiomaps

23 Comments

thank you for the article ...but in my case google maps activity option does not cone in current project.. If I create new project and follow the steps , it works , but if i am trying to add google maps ..then I can not !!!

Thanks for sharing a knowledgeable article for android apps development https://www.cooperativecomputing.com/services/mobile-app-development/android

This is a good blog for developer and thanks for sharing such a good idea of android application development and it is the best way to learn our weekness.

http://dfssssghjrtbz.com/ generic cialis fast delivery cialis tadalafil work

viagra from canada viagra on line with prec viagraiy.com generic viagra safe http://viagraiy.com/ Viagra generico online http://viagraiy.com/ generic viagra online http://fleenorenterprises.com/__media__/js/netsoltrademark.php?d=viagraiy.com how to order viagra without pre buy cheap viagra in canada

canadian pharmacies shipping to usa Northwest Pharmacy canadianpharmacytousa.com best canadian mail order pharmacies http://canadianpharmacytousa.com/ canada rx http://canadianpharmacytousa.com/ online pharmacies http://touriosity.com/__media__/js/netsoltrademark.php?d=canadianpharmacytousa.com canadian pharmacies that are legit http://lab-ndt.ru/bitrix/redirect.php?event1=&event2=&event3=&goto=http://canadianpharmacytousa.com/ canadian discount pharmacies in ocala fl

Cialis 20mg cialis from usa pharmacy cialisvus.com cialis pills for sale http://cialisvus.com/ cialis prices http://cialisvus.com/ Cialis 20 mg http://socialsecurityadvice.org/__media__/js/netsoltrademark.php?d=cialisvus.com can you buy viagra in mexico without a prescription http://xn--80aa1bjf.xn--p1ai/bitrix/redirect.php?event1=&event2=&event3=&goto=http://cialisvus.com/ buy cialis online safely

canadian prescriptions online canada vagra canadianpharmacyonli.com are canadian online pharmacies safe http://canadianpharmacyonli.com/ canada rx http://canadianpharmacyonli.com/ canada online pharmacies http://tradingdogs.com/__media__/js/netsoltrademark.php?d=canadianpharmacyonli.com canadian pharmacy no prescription http://sborschikmebeli.su/bitrix/redirect.php?event1=&event2=&event3=&goto=http://canadianpharmacyonli.com/ northwest pharmacies online

cialis without a doctor's prescription in usa buy cialis no rx cialisonl.com cialis online http://cialisonl.com/ cialis prices walmart http://cialisonl.com/ cialis purchase online without prescription http://seejanetri.com/__media__/js/netsoltrademark.php?d=cialisonl.com cheap cialis without a doctors prescription

Cialis canada generic cialis tadalafil uk cialisb.com cialis cena http://cialisb.com/ cialis 5 mg side effects http://cialisb.com/ Best buy canada online http://skycigfreedom.com/__media__/js/netsoltrademark.php?d=cialisb.com real cialis without a doctor's prescription http://a03.su/bitrix/redirect.php?event1=&event2=&event3=&goto=http://cialisb.com/ buy tadalafil no prescription

viagra on line viagra pills definition viagraiy.com viagra generica pedido en espanol http://viagraiy.com/ viagra pills 100 mg http://viagraiy.com/ generic viagra http://thecartermarioway.com/__media__/js/netsoltrademark.php?d=viagraiy.com viagra without doctor visit buy viagra with no prescription

canadian pharmacies online pharmacy canada reviews canadianpharmacytousa.com canadian drugstore http://canadianpharmacytousa.com/ canada pharmaceuticals online http://canadianpharmacytousa.com/ canadian online pharmacies http://touriosity.com/__media__/js/netsoltrademark.php?d=canadianpharmacytousa.com buy viagra now http://vwvoronezh.ru/bitrix/redirect.php?event1=&event2=&event3=&goto=http://canadianpharmacytousa.com/ online pharmacy canada

buy cialis with prescription buy cheap cialis in canada cialissy.com cialis online http://cialissy.com/ cialis anda litigation http://cialissy.com/ cialis purchase online without prescription http://teaco.ru/bitrix/rk.php?goto=http://cialissy.com/ tadalafil without prescription

Buy cialis online cialis generico online cialisvv.com cialis online http://cialisvv.com/ cialis 20 mg coupon http://cialisvv.com/ Buy cialis http://meetroommates.com/__media__/js/netsoltrademark.php?d=cialisvv.com cialis without prescriptions http://baubau-coal.com/bitrix/redirect.php?event1=&event2=&event3=&goto=http://cialisvv.com/ buy tadalafil no prescription

buy viagra viagra pills for men viagravipsale.com Viagra 5mg http://viagravipsale.com/ viagra pills at walmart http://viagravipsale.com/ viagra generic http://ftmyerstouristcenter.com/__media__/js/netsoltrademark.php?d=viagravipsale.com cheap viagra without script buy viagra cheap

drugstore online northwest pharmacies canadianpharmacyonli.com canadian pharmacies-24h http://canadianpharmacyonli.com/ Northwest Pharmacy http://canadianpharmacyonli.com/ online pharmacies canada http://tradingdogs.com/__media__/js/netsoltrademark.php?d=canadianpharmacyonli.com candida viagra http://ric32.ru/bitrix/rk.php?goto=http://canadianpharmacyonli.com/ canadian medications list

cialis without a doctor's prescription in usa cialis 5 mg daily cialissi.com tadalafil without a doctor's prescription http://cialissi.com/ cialis 5 mg http://cialissi.com/ cialis purchase online without prescription http://ukoutsourcedhelpdesk.net/__media__/js/netsoltrademark.php?d=cialissi.com buy cialis online without a prescription

Cialis prices cialis cena apoteka cialisiv.com tadalafil 10 mg http://cialisiv.com/ cialis 5 mg price walmart http://cialisiv.com/ Cialis pills http://usedeticket.com/__media__/js/netsoltrademark.php?d=cialisiv.com cialis without a doctor's prescription from canada http://busauto.ru/bitrix/redirect.php?event1=&event2=&event3=&goto=http://cialisiv.com/ buy cialis online us pharmacy

cialis without a doctor's prescription in usa cialis vs viagra cialissi.com buy tadalafil http://cialissi.com/ 20mg cialis lowest price http://cialissi.com/ tadalafil without a doctors prescription http://airportlighting.org/__media__/js/netsoltrademark.php?d=cialissi.com cialis daily use without prescription

real cialis without a doctors prescription generic for cialis cialisonl.com buy cialis online best price http://cialisonl.com/ tadalafil generic 20mg http://cialisonl.com/ tadalafil without a doctor's prescription http://automation-st.ru/bitrix/redirect.php?event1=&event2=&event3=&goto=http://cialisonl.com/ cialis without a doctors prescription in usa

cialis without prescription cialis without a doctor's prescription cialissv.com cialis 5 mg side effects http://cialissv.com/ tadalafil tablets 10mg http://cialissv.com/ tadalafil without a doctor's prescription http://jimfrazee.com/__media__/js/netsoltrademark.php?d=cialissv.com cialis without doctor prescription

how to buy cialis without a prescription generic cialis tadalafil fast cialissv.com cialis prices 10mg http://cialissv.com/ buy tadalafil pills http://cialissv.com/ cialis no doctor's prescription http://spherocult.com/__media__/js/netsoltrademark.php?d=cialissv.com can you buy cialis without a prescription

cheap cialis without prescription buy cialis cialissy.com cialis cena srbija http://cialissy.com/ cialis tadalafil 40mg http://cialissy.com/ can you buy viagra without prescription http://allisonhendrick.com/__media__/js/netsoltrademark.php?d=cialissy.com can you buy viagra in mexico without a prescription

Leave a reply

Your email address will not be published. Required fields are marked *

Comment

Name

Email

Social Comments
Go top