Guide: Google Maps V2 for Android : Creating your Google Map Application:

If you already got your Google Maps Android API V2 key then you are ready to create
your map application. If you don’t head to my Guide: Google Maps V2 for Android :
Getting the API key
post to read how to get it.

So lets start:
1. Open Eclipse and create a new Android project.
The first thing that we will handle is the import of Google Map classes.
To get the Google Maps files we need to download the last version of
Google Play Services via the Android SDK Manager.

2. After you downloaded the Google Play Services, restart Eclipse and
in the Package Explorer Right-Click –> Import….
In the opened windows choose “Existing Android Code into Workspace” and click “Next”.
Click the “Browse…” Button and head to the location of your SDK folder.
in it find the following folder:

\extras\google\google_play_services\libproject\google-play-services_lib

and press “OK”, check the V next to it in the window and press the “Finish” button.

3. Now you added Google Play Services to your work space, we have to create a reference
from our project to this library. Right-Click your project and choose “Properties” go
to the Android section, in the lower part press the “Add…” button and add a reference
to that library. Your result should be as in the screen shot bellow:

adding google play services library

Note: If you try to reference google-play-service library and you receive a red X next to this
reference, what you should do is to move the .jar file to a location where it’s path will be shorter
and then reference it again.

4. Another import we have to make in order to make our application work on
Operation system prior to API11 is to import the support library this can be done very easily
using Eclipse: Right-Click you project and choose “Android Tools” and then choose
“Add Support Library…”:

supportlibrary

When you finish those import you should have the following libraries (Red) in the
Android Dependencies folder (Green) of your project:
Untitled

5. We are now ready for some codding: First of all open the Android Manifest file:
add the following permissions:

<permission android:name="your.application.package.permission.MAPS_RECEIVE" android:protectionLevel="signature"/>
<uses-permission android:name="your.application.package.permission.MAPS_RECEIVE"/>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

Important: Replace your application package instead of the current “your.application.package” string.

As mentioned in the comments by @Keilaron it looks like since the Google Play Services
3.1.59 update the MAPS_RECEIVE permissions are completely unnecessary and as a result
they can be removed.

6. Next, Google Maps uses OpenGL so we have to add OpenGL support to our application
by adding this to the Manifest file:

<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>

7. Finally add your key to you application right before you close your “application” node
in the Manifest file:

<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="Your Google Maps API V2 Key" />

8. Now create an Activity that extends from “FragmentActivity”:

import android.os.Bundle;
import android.support.v4.app.FragmentActivity;

public class MapActivity extends FragmentActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.map_layout);
    }
}

9. Finally for map_layout, XML layout file that was set
as a content view of the map activity write the following:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <fragment
        android:name="com.google.android.gms.maps.SupportMapFragment"
        xmlns:map="http://schemas.android.com/apk/res-auto"
        android:id="@+id/map"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
</LinearLayout>

10. UPDATE: The last update for Google Play Services library revision 13 introduced
a new meta-data tag that should be added as well to your Android Manifest file.
So go ahead and add this right next to your API key meta-data code:

<meta-data 
android:name="com.google.android.gms.version" 
android:value="@integer/google_play_services_version" />

And that’s it, run the application and you should see a full screen map:

map

Remember that if you want to run the application in the emulator you should install
Google Play Services first.

Enjoy and stay tuned.

122 Responses to this entry

  • Basicorex Says:

    Hey, it’s me the guy from Stackoverflow who asked how to stop making your Android Google Maps App to stop crashing and you said that I should follow steps 2-4 which I had done before posting there, so I’m wondering how do you suggest I stop it from crashing? I am using an android phone to run the app if you were wondering(which is needed since google play doesn’t work on normal emulator).

    Posted on March 12th, 2013 at 9:55 pm Reply | Quote
  • Emil Adjiev Says:

    @Basicorex actually there is a way to use the emulator with Google maps, you can read about it here:
    Google Maps V2 in the Emulator. About your problem, it’s really hard to help someone without all the details. Please don’t describe the problem here, bur ratter post a link to the SO question.

    Posted on March 13th, 2013 at 8:00 am Reply | Quote
  • Sameer Hussain Says:

    Thanks for the help. But now the emulator says update your google play services!

    Posted on March 13th, 2013 at 12:43 pm Reply | Quote
  • Emil Adjiev Says:

    @Sameer Hussain read my next post to fix this: Google Map in Emulator

    Posted on March 13th, 2013 at 7:42 pm Reply | Quote
  • Dave Says:

    Quick question, I have this working for a sample application to test a proof of concept (POC), worked great, now I’m creating a new Android project (hopefully to be deployed to public), followed all the steps, but it’s not working, fails some where in setContentView on in the onCreate process of the MainActivity . Registered a Key for Android app on the Google APIs. Since both projects are using the same debug.keystore I end up with something that looks like this on Google API Services:

    38:C8:A9:92:8F:78:86:D3:0C:0E:29:01:CE:2B:D8:02:A5:66:54:3C;com.example.mapexample (this one works fine and was registered first for API Access)
    38:C8:A9:92:8F:78:86:D3:0C:0E:29:01:CE:2B:D8:02:A5:66:54:3C;com.company.mapit

    (obviously SHA1 is not my real number). Is it possible that using the same SHA1 for both projects is causing the problem? I have checked and quadrupled check that the code is consistent everywhere, proper libraries are used (android-support-v4.,jar, etc.) I can’t get far enough into the application to effectively debug it because the code takes off outside my project. This is the run sequence:

    1. White Screen when app is loading, title of app is showing – map never shows.
    2. Sorry! The application mapit (process com.company.mapit) has stopped unexepectedly. Please try again. A single button (Force Close).
    3. Application ends

    This happens in both Run and Debug mode. I am stuck – I have verified that everything is defined the same way as the other project – it is, libraries are mapped correctly etc.

    Application is written for Minimum 10 – (need to work on 2.3.6 phones) Max. 17 (4.2.2).

    Thanks in advance.

    Posted on March 14th, 2013 at 5:43 am Reply | Quote
  • Emil Adjiev Says:

    @Dave My suggestion to you would be to go to your API console and create a new Project in the console as describe here: Google Map API V2 Key just to make sure it not a key/project problem. next embed the key in your project and run it. if you still have a problem, post a question on SO with your full stack trace, and post here a link, I will try to help you. I just have to say that I didn’t had the chance yet to publish a Google Map application on the market so I have no idea what should be changed regarding the Key for the Release version.

    Posted on March 14th, 2013 at 7:44 am Reply | Quote
  • Seyf Says:

    Hi Emil, thanks for this great tutorial !!! :)

    so this project works well with me, but i want to use GoogleMap object with this line code:

    GoogleMap gMap = ((MapFragment)getFragmentManager().findFragmentById(R.id.map)).getMap();

    but it didn’t work with me for this two reasons:

    - I have a galaxy s2 using android 2.3.4 so in the manifest file i’m using minSdk =8
    =>Call requires API level 11 (current min is 8): android.app.Activity#getFragmentManager
    - I am not sure if this is the right method to get the map.

    Do you have any comments or ideas ? and thanks again :)

    Posted on April 1st, 2013 at 6:34 pm Reply | Quote
  • Emil Adjiev Says:

    To get the instance of the map in API levels bellow 11 use the SupportMapFragment, and this method:
    [java]
    map = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
    [/java]

    Posted on April 1st, 2013 at 10:28 pm Reply | Quote
  • Seyf Says:

    @Emil Adjiev thank you so much ! it works ! :)

    Posted on April 2nd, 2013 at 2:09 pm Reply | Quote
  • Emil Adjiev Says:

    You welcome, @Seyf : )

    Posted on April 2nd, 2013 at 2:11 pm Reply | Quote
  • RG Says:

    Thanks a lot :D

    Posted on April 8th, 2013 at 3:51 pm Reply | Quote
  • Nanees Says:

    i’ve made these steps multiple times .. and each time it stops at the same part .. i’ trying to run the google maps v2 ..
    but in the step of adding the google-play-service-lib as a reference for my projects .. after adding and applying and pressing ok , the library doesn’t appear to me in both the folders (Android 2.2) and (Android Dependencies) i don’t know where is the problem, could u please help me to find it out :)

    Posted on April 12th, 2013 at 2:29 pm Reply | Quote
  • Emil Adjiev Says:

    @Nanees, First of all try to restart Eclipse and clear the project.
    If this doesn’t help you, check in the properties of the project that you see a green V next
    to the google-play-services library referencing, if not you can try to move this jar file
    to a location where it’s path will be shorter and try to reference it again.

    Posted on April 12th, 2013 at 4:04 pm Reply | Quote
  • Nanees Says:

    After clearing the project and restarting eclipse ,, there is no a green V mark beside the referenced lib, but there is a red cross

    Posted on April 12th, 2013 at 4:11 pm Reply | Quote
  • Emil Adjiev Says:

    So as I said: try to move this jar file to a location where it’s path will be
    shorter and try to reference it again. you can try to update the google-play-services
    using the SDK manager and do the referencing again as well.

    Posted on April 12th, 2013 at 4:14 pm Reply | Quote
  • Nanees Says:

    i removed the Google play service from the SDK manager , and re-installed it again, then i’ve made those steps and restarted my eclipse then the same red cross appeared to me, this time i’ve change the path and put the folder (google-play-service-lib) direct in the C drive

    Posted on April 12th, 2013 at 4:24 pm Reply | Quote
  • Emil Adjiev Says:

    Strange, usually those steps fixed it for me.
    Maybe there is some thing wrong with your project.
    what happens when you try to reference this jar file
    from another project?

    Posted on April 12th, 2013 at 5:22 pm Reply | Quote
  • Nanees Says:

    @Emil Adjiev

    i tried referencing the jar files to all the projects i have and it gives me the same red cross :(

    Posted on April 14th, 2013 at 3:55 pm Reply | Quote
  • Nanees Says:

    @Emil Adjiev

    Now i’ve solved the issue of referencing by clicking the check box of copy the project to my workspace when importing the library..
    the maps page opened but it only loads a white blank page with zoom in and out.
    In the logcat: (Unable to load google maps) was wriiten

    Posted on April 14th, 2013 at 7:11 pm Reply | Quote
  • Emil Adjiev Says:

    @Nanees usually when you receive a blank screen with zoom controls then you have some problem with your key, or with the configurations you made in the API Console:
    Try to go over this post: Google Maps API key and make sure that you have completed all the steps. If you positive that
    you did you can try to remove the dubug.keystore folder, compile some project in eclipse (That will result in regenerating a new debug.keystore folder and a new SHA1 key) and
    do the registration with the new key.

    Posted on April 14th, 2013 at 7:36 pm Reply | Quote
  • frank Says:

    Hi Emil,

    For step 8 & 9 are these new files I need to generate or do I use my previously coded files? I’m not sure where to put this information.

    thanks
    frank

    Posted on April 15th, 2013 at 5:06 am Reply | Quote
  • Emil Adjiev Says:

    @frank, for step 8 you need to create a new java class file in the src folder of your project and paste there the code. for step 9 you new to create a new layout xml file and put it inside the res/layout folder.

    Posted on April 15th, 2013 at 9:30 am Reply | Quote
  • BRShooter Says:

    I use Eclipse-ADT, have problem?
    I create a new class but have error. Have which one Main?
    Because a new class created show PUBLIC CLASS FRAGMENTACTIVITY

    Posted on April 19th, 2013 at 3:45 pm Reply | Quote
  • Ed Says:

    Just gotta say, thank you for the concise write-up. I was following the Google Developer Guide to get a basic map to show up, and was ready to go to bed defeated!

    Knowing about the Android Dependencies will hopefully save me a lot of time in the future.

    Cheers!

    (Linked from Stack Overflow)

    Posted on April 22nd, 2013 at 8:06 am Reply | Quote
  • Emil Adjiev Says:

    @Ed you welcome, it’s nice to see that it helps other people. you are welcome to send me questions if you encounter problems.

    Posted on April 22nd, 2013 at 10:27 am Reply | Quote
  • Emil Adjiev Says:

    @BRShooter I didn’t understand what is the problem you encounter.

    Posted on April 22nd, 2013 at 11:37 am Reply | Quote
  • Mayada Says:

    Emil , I followed all steps using libraries of Google play services r#4 but there is an error in .xml file at this line ” xmlns:map=”http://schemas.android.com/apk/res-auto”” which is ” unexpected namespace prefix “xmlns” found for tag fragment
    when I delete this line it works with zoom levels only but there is no map appears
    Could you tell me what can I do?

    Posted on April 25th, 2013 at 6:00 am Reply | Quote
  • Emil Adjiev Says:

    @Mayada As it look you are describing two problem that are not related one to another:
    1. the problem with the name space can derive from two reason:
    a. you didn’t performed the first 3 steps correctly and didn’t reference the google-play-service library as needed.
    b. there is a bug with those the “map” prefix if you put you map fragment with other components on one screen.
    2. the second problem where you see only the zoom controls and not the map, is related to some sort of API key problem.
    Either you didn’t produced as you should or you didn’t register it in to API Console the right way, take a look at this blog post and make sure you commit all the steps correctly: Google Maps API V2 Key

    Posted on April 25th, 2013 at 10:23 am Reply | Quote
  • Mayada Says:

    Thanks Emil it works
    could you tell me how to do navigation?

    Posted on April 25th, 2013 at 9:37 pm Reply | Quote
  • Emil Adjiev Says:

    @Mayada if you want to implement navigation between two point, take a look at this
    answer I gave here: Draw driving route between 2 LatLng on GoogleMap SupportMapFragment

    Posted on April 26th, 2013 at 12:40 pm Reply | Quote
  • Mayada Says:

    Hi , Emil
    I tried code here : http://stackoverflow.com/questions/16125868/draw-driving-route-between-2-geopoints-on-googlemap-supportmapfragment/16126547#16126547
    but with error ” No such file or directory”
    Could you tell me what can I do ?

    Posted on April 28th, 2013 at 2:24 pm Reply | Quote
  • Emil Adjiev Says:

    @Mayada Please open a new question on SO with the full stack trace and post here a link and I will try to help you. It’s impossible to know what the problem is from “No such file or directory” error.

    Posted on April 28th, 2013 at 4:14 pm Reply | Quote
  • Mayada Says:

    Hi ,Emil
    There is an error in class “GetDirectionsAsyncTask” in function “public void onPreExecute()” @ DialogUtils it doesn’t defined
    and @ “onPostExecute” function there is an error @ ” activity..handleGetDirectionsResult(result)” where I defined function “handleGetDirectionsResult(result) ” in MainActivity
    what can I do?

    Posted on April 29th, 2013 at 7:42 am Reply | Quote
  • Emil Adjiev Says:

    @Mayada As I already said open a new question on SO, and I will help you there.

    Posted on April 29th, 2013 at 11:48 am Reply | Quote
  • Kevin Kaburu Says:

    I have refferenced the library and all went on well but, I could not run the emulator since this new error came up >>>[2013-05-10 04:15:24 - APPNAME] Could not find APPNAME.apk!

    Posted on May 10th, 2013 at 2:40 pm Reply | Quote
  • Emil Adjiev Says:

    @Kevin Kaburu it look like Eclipse has some problem creating your .apk file. you could try restart Eclipse, this usually solves this problem for me.

    Posted on May 10th, 2013 at 9:24 pm Reply | Quote
  • shal Says:

    @Emil

    This line in the xml file:

    xmlns:map=”http://schemas.android.com/apk/res-auto”

    Gives error: Unexpected namespace prefix “xmlns” found ifor fragment tag

    Why is that ?

    Posted on May 12th, 2013 at 9:37 pm Reply | Quote
  • Emil Adjiev Says:

    @shal you can remove this line if you are not using any of the map prefix properties.
    For your question this could be caused by 2 reasons:
    1. There is a bug with Google maps that this “map” namespace can’t be found if the map fragment is not the only thing you have in your layout.
    2. Another cause of this could be that there is some problem with the way you reference the google-play-services_lib.

    Posted on May 13th, 2013 at 10:51 am Reply | Quote
  • Suraj Says:

    I will do all the things but map is not display ,it show white screen with zoom controller
    and it give me error Like:

    05-16 12:26:00.351: E/Google Maps Android API(8366): Failed to load map. Error contacting Google servers. This is probably an authentication issue (but could be due to network errors).

    Posted on May 16th, 2013 at 10:13 am Reply | Quote
  • Emil Adjiev Says:

    @Suraj usually this problem happens when you have some problem with the way you generated you API key or the way you registered it in the Google API Console, please check this guide on Google Maps API V2 Key and make sure you are doing all the step correctly.
    Also make sure that you have added this permission in you Manifest file:
    [xml]
    <uses-permission android:name="android.permission.INTERNET" />
    [/xml]

    Posted on May 16th, 2013 at 10:50 am Reply | Quote
  • cc10 Says:

    Hi Emil,

    this was really helpful in order to get started with a simple app from scratch. Would you happen to know how one would go about converting a more complex app that uses v1? Is it possible to use the v2 api key with v1 code? The app I’m referring to is: https://github.com/Ryan-ZA/MockGPSPath

    It looks to me like everything needs to be changed, but there are no direct correlations between v1 and v2 functions

    Posted on May 29th, 2013 at 12:39 am Reply | Quote
  • ranjan Says:

    the public type MapActivity must be defined in its own file….this is the error message after step 8

    Posted on May 29th, 2013 at 11:26 am Reply | Quote
  • Emil Adjiev Says:

    @cc10 Hi Ryan, Sorry to be the one that gives you the bad news, but no there is no a quick way to go from Google Maps API V1 to Google Maps API V2 nor you can use the new API key with the old code (the keys are even produced differently). Most of the object have changed and you will have to replace them. So MapView becomes MapFragment or SupportMapFragment. MapActivity will be a simple Activity or a FragmentActivity for backward compatibility for Fragments. Overlays should be recreated as Polylines or Polygones depending on what you want to create.
    So no there is no a quick and simple way but most of the functionality is really straight forward.

    Posted on May 29th, 2013 at 11:38 am Reply | Quote
  • cc10 Says:

    @Emil Adjiev

    thanks for the quick reply, i will see if it makes sense to convert the app, but I have a feeling it could be much quicker to simply write the map-related code from scratch.

    Posted on May 29th, 2013 at 3:47 pm Reply | Quote
  • Emil Adjiev Says:

    @cc10 I have the feeling that you are right about it. Take some time to learn the new API and start everything from scratch.

    Posted on May 29th, 2013 at 5:20 pm Reply | Quote
  • Emil Adjiev Says:

    @ranjan As the error clearly states: “public type MapActivity must be defined in its own file” you probably did not defined this class in it’s own java file.

    Posted on May 29th, 2013 at 5:22 pm Reply | Quote
  • kriszsomogyi Says:

    I’ve followed Googles instructions over and over and i couldnt get it working, but i came across this site and it worked straight away….Moments earlier I was screaming in relief. THANK YOU!

    Posted on June 4th, 2013 at 2:59 am Reply | Quote
  • Benzabill Says:

    Hello Emil,
    Google Maps is now on API v3 and i can not make the maps work on my device! Could you look at my SO question that I have just posted?

    I am getting the error that I am pretty sure corresponds to having a faulty API key but I am using the androiddebugkey.

    Thanks for the help!

    Posted on June 13th, 2013 at 11:47 pm Reply | Quote
  • Emil Adjiev Says:

    @Benzabill The latest native Google API version for android is V2. V3 is for web development. So I guess that this mix up is your mistake. If you need any other help please post a link to your SO question.

    Posted on June 16th, 2013 at 2:56 pm Reply | Quote
  • Benzabill Says:

    Hello @Emil

    I am trying to add markers to the map that i created using your tutorial. However it seems that i have to use a GoogleMaps object to do something like this. How do I do that?
    NOTE: I am trying to support API 8 and above so I am using SupportMapFragment

    Thanks

    p.s. i tried a different tutorial that created a GoogleMaps object but got error on the .getMap() section so I am wondering if it is possible to do things like that to your map.

    Posted on June 17th, 2013 at 8:34 pm Reply | Quote
  • Benzabill Says:

    I meant to say SupportMapFragment object rather than GoogleMaps object. getMap() returns a GoogleMaps object.
    Thanks again

    Posted on June 17th, 2013 at 8:37 pm Reply | Quote
  • Emil Adjiev Says:

    @Benzabill To get the instance of the map in API levels bellow 11 use the SupportMapFragment, and this method:
    [java]
    map = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
    [/java]
    Then you can added a marker to it:
    [java]
    newmarker = map.addMarker(new MarkerOptions().position(latlng).title("Title").icon(BitmapDescriptorFactory.fromResource(R.drawable.marker)));
    [/java]

    Posted on June 18th, 2013 at 11:52 am Reply | Quote
  • jeetu Says:

    h sir i have try your post several time in my eclipse for run map but every time same problem GoogleMap.apk not found

    i am run my eclipse on window xp 2002

    please tell me how run google map on android emulator

    thank you

    jeetu dagar

    jeetu.dagar029@gmail.com

    Posted on June 24th, 2013 at 12:03 pm Reply | Quote
  • Emil Adjiev Says:

    @jeetu First of all it’s impossible to run a Google Map API V2 application on the emulator out of the box. You can go over this blog post link to get an idea on how to run Google Maps API V2 on an emulator, go over the comments as well as there are new links for new set of files you will need to install.

    Posted on June 24th, 2013 at 12:39 pm Reply | Quote
  • Bianca Says:

    Thank you for the post! Now I finally got the map to work in my application :)

    Cheers,
    Bianca

    Posted on July 9th, 2013 at 1:34 am Reply | Quote
  • Emil Adjiev Says:

    @Bianca you welocme, have a nice coding : )

    Posted on July 9th, 2013 at 2:08 pm Reply | Quote
  • Peter Says:

    Hi Emil,

    I have been able to get the map working. However, regarding step 4, I only have “google-play-services_lib.jar” under my Android Dependencies. I don’t have “google-play-services.jar” or “android-support-v4.jar”.

    Since the map still works, I was wondering if these were supposed to be necessary or if you could tell me why it is not there and how I could get them to appear.

    Thanks!

    Posted on July 16th, 2013 at 1:36 am Reply | Quote
  • Emil Adjiev Says:

    @Peter If your map showing and everything is working then you have nothing to worry about. Google have made some changes recently in Eclipse with the way your added libraries are showing in the Explorer, so you will not nececerly will see all those files.

    Posted on July 16th, 2013 at 3:40 am Reply | Quote
  • Pankhuri Says:

    Hello sir,
    sir i have followed all ur steps…but still than its not working. Initially it was prompting to update your Google Play Services with an Update Button but not after some corrections it has stopped working completely. Its crashing even after many attempts…sir plzz help me its mine college [projects and it means a lot to me.. :(

    Posted on July 20th, 2013 at 8:28 pm Reply | Quote
  • Emil Adjiev Says:

    @Pankhuri I can’t help your without clearly understanding what you problem is. Please post a question on SO with all the needed information and code file, and post here a link. Then I could try to help you.

    Posted on July 21st, 2013 at 2:33 am Reply | Quote
  • danssky Says:

    Hi Emil, i tried your tutorial for maps v2. honestly i am really the beginner and i have a problem. poof! “unfortunately, DANARGPS has stopped.” (my app name was “DANARGPS). really need your share, coz this i build for my thesis. thankyou very much.

    Posted on July 22nd, 2013 at 12:31 pm Reply | Quote
  • Emil Adjiev Says:

    @Danssky there is no way for me to help you if you don’t provide me with you code and other related details.
    Please post a question on SO and post here a link so I could try to help you.

    Posted on July 22nd, 2013 at 5:57 pm Reply | Quote
  • Adam Says:

    Great tutorial!

    I have an app up and running that displays the map and markers for various locations however when I double tap to zoom in or pinch to zoom in the map goes into a loop of trying to locate the markers that it had previously located. Any thoughts on why the zooming would cause a problem on the map?

    Thanks

    Posted on July 22nd, 2013 at 8:59 pm Reply | Quote
  • Emil Adjiev Says:

    @Adam, I don’t understand what do you mean by: ” the map goes into a loop of trying to locate the markers that it had previously located”, and I can’t really help you without seeing your code.
    Please post a question on SO and post here a link so I could try to help you.

    Posted on July 23rd, 2013 at 4:57 pm Reply | Quote
  • sourabh Says:

    I am trying to get android-support-v4.jar and google-play-services.jar in android dependencies but not able to get. tried with android-tools > add support library. it is always asking me to install support library rev 18. i did it but getting some warning “Warning: Ignoring sample ‘downloaded’: does not contain source.properties.” so android tools method also fails. please help me if it is necessary to get both jar in android dependencies and any alternate way is there.

    Posted on July 26th, 2013 at 5:09 pm Reply | Quote
  • Robert Says:

    Thanks for the tutorial. It helped a lot. Now… How do I make the map zoom to my current location?

    Posted on July 31st, 2013 at 3:13 am Reply | Quote
  • Emil Adjiev Says:

    @Robert You welcome, for your location you can use the build in setMyLocationEnabled(boolean) method or implement your own LocationListener that will be invoked on location change of the device. You can find a lot of examples on the web, and I guess I will make a guide soon as well.

    Posted on July 31st, 2013 at 7:09 pm Reply | Quote
  • Keilaron Says:

    I was wondering why this tutorial differs from the documentation in terms of the permissions.

    Turns out:
    “MAPS_RECEIVE is now completely unnecessary. The latest update of Google Play Services 3.1.59 made it useless. As a result, it can be removed.”
    Source: https://plus.google.com/118417777153109946393/posts/Dk65EACXqsh

    Posted on August 1st, 2013 at 10:37 pm Reply | Quote
  • Emil Adjiev Says:

    Thanks @Keilaron. I wasn’t aware of that and this tutorial was written before this update when this permission was necessary so this is the reason it’s there. Thanks again for the information, I will update this post with the information you have provided.

    Posted on August 1st, 2013 at 10:48 pm Reply | Quote
  • issaac Says:

    hi,

    i’m getting map but its blank

    Posted on August 2nd, 2013 at 5:11 pm Reply | Quote
  • Ravi Shanker Yadav Says:

    I have trouble with Android Google map,
    Please Solve My Problem. Thank You.

    Posted on August 3rd, 2013 at 5:48 pm Reply | Quote
  • Emil Adjiev Says:

    @issaac without the relevant information I can’t help you. Please post a question on Stackoverflow and post here a link, and I will try to help you.

    Posted on August 4th, 2013 at 10:59 am Reply | Quote
  • Emil Adjiev Says:

    @Ravi Shanker Yadav Please don’t pollute the comment section with a huge amount of code, post all this information on Stackoverflow and post here a link and I will try to help you.

    Posted on August 4th, 2013 at 11:03 am Reply | Quote
  • Franz Klein Says:

    I have followed the instructions but get a blank map view which only shows the zoom buttons in the bottom right hand corner. I have used a MapFragment instead of the SupportMapFragment (all references in your code have been replaced with a reference to MapFragment in my code).

    Posted on August 16th, 2013 at 12:12 pm Reply | Quote
  • Rich Fesler Says:

    After 3 days of pulling hair …thank you! Been a bytch getting v2 to work on API 9 through API 17.

    Posted on August 16th, 2013 at 11:58 pm Reply | Quote
  • Emil Adjiev Says:

    @Franz Klein I need to see your code in-order to help you. In general with those symptoms it’s there is some problem with your defined permissions or the way you configured your API Console. Please post a question on Stackoverflow and post here a link and I will try to help you.

    Posted on August 18th, 2013 at 11:22 am Reply | Quote
  • sanna Says:

    xmlns:map=”http://schemas.android.com/apk/res_auto”

    showing error

    Posted on August 19th, 2013 at 9:36 am Reply | Quote
  • Emil Adjiev Says:

    @sanna you can remove this line.
    In this example it will work without it.

    Posted on August 19th, 2013 at 4:00 pm Reply | Quote
  • Franz Klein Says:

    @Emil Adjiev I have discovered what the problem was. In the Google APIs Console I had switched on the Google Maps API v2 and not the Google Maps Android API v2. With Google Maps Android API v2 switched on it works.

    Posted on August 21st, 2013 at 4:28 pm Reply | Quote
  • CodeNinja Says:

    MAAAAAAN you are the best finally worked . Thanks a lot

    Posted on September 20th, 2013 at 2:36 pm Reply | Quote
  • Thayar Says:

    If I run the simple google map app in the device with version 2.3.6.
    i got an message like this:
    This app won’t run unless you update google play services
    I’m not running in the emulator.
    Please help me to resolve this

    Posted on September 21st, 2013 at 11:57 am Reply | Quote
  • Emil Adjiev Says:

    @Thayar Hi, maybe google doesn’t provide the up to date version of Google play services for your device or the android version in it. you can try to remove google play services from your and run your Google Maps application again. Now you should receive the option to update google play services from the Play Store. Good luck.

    Posted on September 22nd, 2013 at 12:45 pm Reply | Quote
  • Manish R Warang Says:

    Thanks a lot for the detailed information. You made my day !!!

    Posted on October 14th, 2013 at 11:56 am Reply | Quote
  • Srdjan Says:

    Greetings friend,

    I have a problem with this code, or Eclipse in general…
    11-04 15:31:29.354: E/AndroidRuntime(21753): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.wcftestapp/com.example.wcftestapp.MainActivity}: android.view.InflateException: Binary XML file line #7: Error inflating class fragment

    I copied your code entirely and still i get this Error inflating class fragment

    Please help.

    Posted on November 4th, 2013 at 4:33 pm Reply | Quote
  • Emil Adjiev Says:

    @Srdjan are you sure you are referencing the google play services library?

    Posted on November 4th, 2013 at 11:25 pm Reply | Quote
  • Emma Says:

    Emil Adjiev,

    help me , it’s not working
    it’s show a black screen T_T
    don’t know where is the problem i do all the steps cerfully

    Posted on November 5th, 2013 at 6:20 pm Reply | Quote
  • kishore Says:

    Hi Emil ,
    I am getting error 11-06 12:14:12.351: E/AndroidRuntime(4797): Caused by: android.view.InflateException: Binary XML file line #1: Error inflating class fragment . i have followed by all steps . But still getting same error. could you help me .

    Posted on November 6th, 2013 at 8:54 am Reply | Quote
  • Emil Adjiev Says:

    @Emma Sorry, but I can’t help you without any additional information. Please open a question on StackOverflow and paste here a link and I will try to help you.

    Posted on November 6th, 2013 at 8:32 pm Reply | Quote
  • Emil Adjiev Says:

    @kishore Hi, this problem is usually happens when there is a problem in the way you referencing google-play-service or the android-support library. Also it may happen if you are trying to integrate a SupportMapFragment in a simple Activity (and not in a FragmentActivity).

    Posted on November 6th, 2013 at 8:44 pm Reply | Quote
  • Jeelof Says:

    thx for sharing!! helped me alot!! encountered some small problems after I followed this post, had to import the Google Play Services lib project to me workspace before it was referred right (was referring to the android sdk pad first I think). And after importing encountered next problem cus none of the amd emulators where working, only got the white bg, got this error in me logcat “Google Maps Android API(1332): Google Maps Android API v2 only supports devices with OpenGL ES 2.0 and above”. So had to use the genymotion emulators. But after 2 days I finally see some maps :) v1 was so much easier to implement.

    Posted on November 10th, 2013 at 2:04 am Reply | Quote
  • Jeelof Says:

    Oh and almost forgot to mention atm u also have to asign the versioncode in ur project, using the meta value

    Posted on November 10th, 2013 at 2:40 am Reply | Quote
  • Emil Adjiev Says:

    @Jeelof Hey, I guess you right, API V1 was a little more easier, but here you got a lot more futures, and the maps are looking great, about the new meta-data tag, yes you are right, I need to add it to the guide, as this was added in the last google-play-services update. Thank you for your comments and have a great coding.

    Posted on November 12th, 2013 at 7:30 pm Reply | Quote
  • Surbhi Says:

    Hey , I am the same person from Stackoverflow. I just updated my version for Google play services and I have started getting run time errors again ,Can you please help ? I have tried reloading and referencing! Are the updates stored separately?

    Posted on November 13th, 2013 at 3:32 am Reply | Quote
  • Kelvin Says:

    @Kelvin

    I finally made it. I added network permission then i can start the google app.

    Posted on November 14th, 2013 at 8:48 am Reply | Quote
  • Sarah Says:

    Very good thank you! Specially the last including part.
    million thanks.

    Posted on November 14th, 2013 at 9:23 am Reply | Quote
  • Emil Adjiev Says:

    @Surbhi Hey, for the last update of Google Play Service there is another change you have to do in the Manifest file, Check section 10 of this guide.

    Posted on November 14th, 2013 at 12:40 pm Reply | Quote
  • Kelvin Says:

    Hi Emil,

    Thanks for your wonderful tutorial. may I know is it possible yo initiate map fragment in a fragment? I am now using tab host to develop my apps and just wonder if it possible to use map fragment in one of my tab fragment. Thanks in advance!

    Kelvin

    Posted on November 15th, 2013 at 5:05 am Reply | Quote
  • Joel Says:

    This totally helped thank you!

    Posted on November 25th, 2013 at 5:42 am Reply | Quote
  • Prushni Says:

    Nyc tutorial…
    I am creating an app and using map in that.
    Can u give me the code for routing direction?
    The current location will be starting point and destination will be given by user from edit text. when button is pressed, the direction is shown.
    Can u plz help?

    Posted on November 29th, 2013 at 1:40 pm Reply | Quote
  • Emil Adjiev Says:

    @Prushni Hey, you can check this post I wrote for showing the route on the map.
    There is a project file also that you can download and use to understand how it done.

    Posted on November 29th, 2013 at 2:26 pm Reply | Quote
  • Javier Says:

    nunca pense que me tomaria 3 dias para hacer trabajar este ejemplo de mostrar un simple mapa en mi dispositivo android , me fui por todos los foros de internet y hasta consulte en la misma pagina de android developer pero no encontre solucion.. hasta que llegue aquí a tu pagina y por estas dos lineas :

    recien trabajo!!!

    Gracias!!! Saludos desde Perú ( Lima)

    Posted on December 4th, 2013 at 6:13 am Reply | Quote
  • srihari Says:

    @Emil Adjiev

    Hi I tried this tutorial in elipse but
    when iam following step 9. Finally for map_layout, XML layout file that was set

    iam getting error at
    xmlns:map=”http://schemas.android.com/apk/res-auto”
    i.e. Unexperted namespace prifix “xmlns” found for tag fragment
    can i know how to solve this error

    Posted on December 4th, 2013 at 8:25 am Reply | Quote
  • Emil Adjiev Says:

    @Javier Hey, I’m not talking Spanish but someone translated it for me, You welcome and have a nice coding : )

    Posted on December 4th, 2013 at 12:53 pm Reply | Quote
  • Emil Adjiev Says:

    @srihari Hey, If you are not using any of the “map:” properties in the XML layout file, then you simply can remove this line of code : )

    Posted on December 4th, 2013 at 12:54 pm Reply | Quote
  • Shanmuga Narayanan Says:

    Hi Emil Adjiev,

    Great tutorial indeed. Even i was stuck up with same problem by not getting the map displayed on the emulator. I googled a lot for a solution for this map issue, I came across your blog link, and by following up with your tutorial i got it working and now the map is being displayed on the emulator.

    Thanks man.. Keep up the good work

    Regards,
    Shanmuga

    Posted on December 11th, 2013 at 9:56 am Reply | Quote
  • Priya Says:

    Even after adding support library ,under android dependencies it shows only one jar file.

    Posted on December 27th, 2013 at 7:22 am Reply | Quote
  • Saurabh Says:

    Hey Emil,
    We are encountering problem while the app is being launched.
    An error message pops up saying” UNFORTUNATELY APP HAS STOPPED”
    Though we have defined everything properly
    LOG-CAT ERROR:

    **************************************
    E/AndroidRuntime(8266): Caused by: java.lang.IllegalStateException:
    The meta-data tag in your app’s AndroidManifest.xml does not have the right value.
    Expected 4030500 but found 0.

    please do help since we are doing this as our college project and we are really stuck at this

    Posted on December 31st, 2013 at 9:38 am Reply | Quote
  • Emil Adjiev Says:

    @Saurabh Hey, I left just the relevant portion of your logcat out put, you can see
    that you need to add this meta-data tag to you application tag in the Manifest file:

    [java]
    <meta-data
    android:name="com.google.android.gms.version"
    android:value="@integer/google_play_services_version" />
    [/java]

    If you still have a problem with this, then add this tag instead:

    [java]
    <meta-data
    android:name="com.google.android.gms.version"
    android:value= "4030500" />
    [/java]

    Posted on December 31st, 2013 at 1:05 pm Reply | Quote
  • rupesh choudhary Says:

    Thanks a lot Emil, your code work successfully for me now i can load map on device and emulator too.

    Posted on January 1st, 2014 at 9:57 am Reply | Quote
  • Alessandro Says:

    Tnank You. After making the SDK updates of my application stopped working and following the steps mentioned my application is working again.

    Posted on February 23rd, 2014 at 4:40 pm Reply | Quote
  • Kevin Says:

    Hi, I’ve worked through the tutorial and I’m encountering an issue on running the application. The application stops on loading to the phone and the logcat displays the following: java.lang.runtimeexception: unable to start activity ComponentInfo{ …(package specific info here)… android.view.InflateException Binary file line #9 error inflating class fragment. Any recommendations?? Thanks for the website btw, best tutorial on the subject I’ve seen including google’s own website!

    Posted on February 25th, 2014 at 6:41 pm Reply | Quote
  • Emil Adjiev Says:

    @Kevin Hey, this problem usually indicates that you had made some kind of mistake in importing the google-play-services library into your project. Try to go over this process again.

    Posted on February 26th, 2014 at 7:28 pm Reply | Quote
  • Vijay Says:

    Hi,

    Thanks for this great tutorial.
    I want to show specific location(I have the address) on the map on launching of the app. Any idea, how can i do that?

    Posted on February 27th, 2014 at 1:56 pm Reply | Quote
  • Emil Adjiev Says:

    @Vijay Hey, You welcome, glad it helped you. And yes I do have an idea, but this is a very basic task that you could find a guide for on the internet if only you will spend a little time searching Google.

    Posted on February 27th, 2014 at 3:37 pm Reply | Quote
  • Ruchi Says:

    Thanks alot for this helpful tutorial.

    Posted on March 3rd, 2014 at 8:46 am Reply | Quote
  • wala Says:

    Hi! I followed the steps in this tutorial and the getting API key post as well.When I click the button that is supposed to show my map the app stops. Can u help.I feel I read every post and watched every vid there is nothing works :(
    my post http://stackoverflow.com/questions/22311005/android-google-map-v2-unfortunately-app-has-stopped/22311399?noredirect=1#22311399 please check maybe u can help

    Posted on March 11th, 2014 at 3:18 pm Reply | Quote
  • wala Says:

    yeah and some people suggested that maybe because I’m using debugkey keystore.and that I should use eclips to generate keystore…what do u think? help I’m tired been struggling for a whole week!!!!!!!

    Posted on March 11th, 2014 at 3:21 pm Reply | Quote
  • Johannes M Says:

    Hi. Thanks for this tutorial, it helped a lot.
    However, unfortunately my app is still not working correctly. Whenever I open it on my Android phone it instantly shuts down and says: “Unfortunately, My First App has stopped”. I’v been trying to make it work all day, but I simply can’t find any errors.

    Is there some way that you can look at my code and see if there are some stupid mistake? It would mean the world for me.

    Posted on March 14th, 2014 at 1:17 am Reply | Quote
  • Emil Adjiev Says:

    @wala hey, you got an answer on the stackoverflow thread, check it out.

    Posted on March 14th, 2014 at 9:40 pm Reply | Quote
  • Adam Ramos Says:

    I would just like to say you saved me. I just spent the last six hours trying to get maps to show up on my app and the whole reason it kept dying was because the reference to the google-play-service library had an X next to it…
    Thank you so much!

    Posted on April 1st, 2014 at 6:33 am Reply | Quote
  • Carlo Rodríguez Says:

    I followed a couple of tutorials and just this one work for me, thank you.

    Posted on April 8th, 2014 at 2:31 am Reply | Quote
  • Ijaz Muhammad Says:

    Thank You.. Sir… It Helped Out Me…

    Posted on June 15th, 2014 at 10:41 pm Reply | Quote

Leave a comment