Click here to Skip to main content
Click here to Skip to main content
Go to top

Android google map api v2 setup

, 3 Jul 2013
Rate this:
Please Sign up or sign in to vote.
This article shows how to add google maps api v2 to in android projects.

Introduction 

    As you know, after 18th of March 2013, Android Google Api V1 key requests are no more avaible. For those who want to create a map activity, need to get Android Google Api V2 key. So, in this article I will show the steps to get Android Google Api V2 key . 

Background

 For reader, knowing the Eclipse environment , Android sdk and Google Api's will be helpful.  

Using the code   

These are the steps needed to be followed: 

  • Create new android application ( Compile with Google Api  )     
  • Import Google Play Services Lib     
  • Get your SHA1 fingerprint     
  • Get your mapKey by using your SHA1 key     
  • Modify the AndroidManifest.xml  

and thats all, you are ready to go...  

 Create New Android Application  

 

 Import Google Play Services Lib  

  1. Find your google play services lib  which under the path 
 ....\android-sdk\adt-bundle-windows-x86_64-20130522\adt-bundle-windows-x86_64-20130522\sdk\extras\google and move it to your workspace.   

   2. Import this liblary to your Eclipse 

File\Import\Existing Android Code Into Workspace 

 

  3. Add google play service lib to your project by right clicking on your project  properties\android and you will see little button on the buttom-right "add". Just add the google play service lib and click ok.


 

 Get your SHA1 fingerprint  

Go to: 

Window\Preferences   Android\Build      

 find your SHA1 fingerprint and copy that.

 

Go to Google Apis Console Window.  

 

  • Create new project. 

  • Activate the option "Google Maps Android API V2" 
 

  • Click "Create New Android Key" 
 

  • Enter your SHA1 fingerprint followed by '  ; ' and your application package name.
 

 

Modify the AndroidManifest.xml  

 1- Add the following code right before the <application> tag. 



    <permission
        android:name="com.example.osman.permission.MAPS_RECEIVE"
        android:protectionLevel="signature"/>
<uses-permission android:name="com.example.osman.permission.MAPS_RECEIVE"/>
 
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<!-- The following two permissions are not required to use
     Google Maps Android API v2, but are recommended. -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
 
<uses-feature
        android:glEsVersion="0x00020000"
        android:required="true"/>  
 

 2- Add this right before the </application> tag 



      <meta-data
    android:name="com.google.android.maps.v2.API_KEY"
    android:value="YOUR_KEY"/>
  

3-Add this to your main_layout.xml

 
 <span style="color: black; font-family: Consolas, 'Courier New', Courier, mono; font-size: 9pt; white-space: pre;"> </span><RelativeLayout 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:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >
 
<fragment
          android:id="@+id/map"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          class="com.google.android.gms.maps.SupportMapFragment"/>
 
</RelativeLayout>
 

And your MainActivity will be like this:  

import android.os.Bundle;
import android.app.Activity;
import android.support.v4.app.FragmentActivity;
import android.view.Menu;
 
public class MainActivity extends FragmentActivity {
 
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
	}
 

} 

 

  • To use marker on your map, add these codes in to constructor of your MainActivity...,
 
      GoogleMap googleMap;
        googleMap = ((SupportMapFragment)(getSupportFragmentManager().findFragmentById(R.id.map))).getMap();
        LatLng latLng = new LatLng(-33.796923, 150.922433);
        googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
        googleMap.addMarker(new MarkerOptions()
                .position(latLng)
                .title("My Spot")
                .snippet("This is my spot!")
                .icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_AZURE)));
        googleMap.getUiSettings().setCompassEnabled(true);
        googleMap.getUiSettings().setZoomControlsEnabled(true);
        googleMap.animateCamera(CameraUpdateFactory.newLatLngZoom(latLng, 10));  

 

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author


Comments and Discussions

 
Questiongoogle map Pinmemberanamicaa15-May-14 0:02 
QuestionAdd button PinmemberMember 1070470027-Mar-14 13:39 
Questiongoogle map v2 PinmemberRye Salvador25-Mar-14 20:27 
QuestionThe import com.google.android.gms.maps cannot be resolved PinmemberLakshmiNarayan.G9-Feb-14 20:59 
AnswerRe: The import com.google.android.gms.maps cannot be resolved PinmemberdevBilal20-Mar-14 3:09 
GeneralRe: The import com.google.android.gms.maps cannot be resolved PinmemberLakshmiNarayan.G24-Mar-14 19:45 
QuestionI created new project but again this same error occur pls help me sir PinmemberMember 102551852-Jan-14 11:45 
QuestionApplication is force closing... please help me sir PinmemberMember 102551852-Jan-14 11:40 
Questionproblem PinmemberWalaa Al-Showa3-Nov-13 12:47 
QuestionIt works fine PinmemberAliking1229-Oct-13 12:15 
Questionafter all the above process, failing with Google Brifge services [modified] PinmemberHari Babu Suraneni27-Oct-13 23:14 
AnswerRe: after all the above process, failing with Google Brifge services PinprofessionalSafak Tarazan3-Nov-13 1:27 
AnswerRe: after all the above process, failing with Google Brifge services PinmemberTruong Nguyen Quang17-Feb-14 23:04 
Questiongoogle map is not showing PinmemberMember 1009381113-Sep-13 0:14 
AnswerRe: google map is not showing PinprofessionalSafak Tarazan13-Sep-13 0:17 
QuestionNull Pointer Exception Pinmemberashish vijay pandey2-Aug-13 2:05 
AnswerRe: Null Pointer Exception PinprofessionalSafak Tarazan3-Aug-13 23:19 
GeneralRe: Null Pointer Exception Pinmemberashish vijay pandey5-Aug-13 1:12 
GeneralRe: Null Pointer Exception PinprofessionalSafak Tarazan6-Aug-13 1:39 
GeneralRe: Null Pointer Exception Pinmemberashish vijay pandey6-Aug-13 23:04 
QuestionUnable yo view Map PinmemberMember 1009797131-Jul-13 11:52 
AnswerRe: Unable yo view Map PinmemberMember 1009797131-Jul-13 12:27 
QuestionAdding Multiple projects PinmemberMember 1009797127-Jul-13 12:20 
AnswerRe: Adding Multiple projects PinprofessionalSafak Tarazan28-Jul-13 1:15 
GeneralRe: Adding Multiple projects PinmemberMember 1009797131-Jul-13 11:52 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web03 | 2.8.140905.1 | Last Updated 4 Jul 2013
Article Copyright 2013 by Safak Tarazan
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid