I think this topic is not very well documented on Internet, so i hope to help many of you that is in the
situation of not understanding “Why my Google Maps are not showed in my Android app”.
Let’s start with the begining.
MOST IMPORTANT THING!!!
When you click create a project, you MUST select like TARGET NAME: Google API’s
and NOT Android x.x (x= 1.6, 2.0,2.1 ,2.2,etc)
Create a project in android, with a class called Maps.
This class will have a corresponding xml file called maps.xml
Let’s fill this files:
Code for maps.xml:
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent"> <com.google.android.maps.MapView android:id="@+id/mapView" android:layout_width="fill_parent" android:layout_height="fill_parent" android:enabled="true" android:clickable="true" android:apiKey="08271ecDc7XXpW1H7_nRFBRBTzYGC-unvKL5ahA" /> </RelativeLayout>
We elaborate later about that apiKey…You will modify it, but for now copy like this.
Code for Maps.java:
import android.app.Activity; import android.os.Bundle; import com.google.android.maps.MapActivity; public class MapTab extends MapActivity{ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.maps); } @Override protected boolean isRouteDisplayed() { // TODO Auto-generated method stub return false; } }
After you’ve filled these files let’s complete the Android Manifest file with some required info’s:
You MUST put this line before ending of application tag like this:
<uses-library android:name="com.google.android.maps"></uses-library> </application>
Also you must use the following permissions and add them before ending of manifest tag:
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"></uses-permission> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission> </manifest>
After you filled this info either, it’s time to get an API key.
How to get a APIKEY:
First, you need to export what you have done until now.
So, right click on your project and click Export. Then create a new keystore, put a password, complete the info’s, and save the keystore in a file called, let’s say, Mapskeystore.
After you saved the keystore, browse to it, and move it in the directory where you have installed the android sdk. This directory is called android-sdk-windows. Let’s say this folder is located on D:/ drive.
So for this example you will move the file Mapskeystore to the following location:
d:/android-sdk-windows/Mapskeystore
Then you open a cmd( click start-> Run-> and here type cmd)
Will appear a path like(c:/Users/etc), you must change it with your path:
you need to make it: d:/android-sdk-windows
For this example commands are: cd..-> cd..-> d:-> cd android-sdk-windows
Now, being in this folder you need to type:
keytool.exe -list -keystore Mapskeystore
Then it will be asked the password of the keystore.
Pay attention, in cmd will not appear any characters, you just need to write it and press enter.
Even if you do not see anything happen.
After this will be generated a Certificate Fingerprint which looks like this:
57:CA:98:D8:80:6A:4B:79:9F:A7:4E:44:E9:8E:99:05
This code you will enter to Google Website for obtaining a free GoogleMaps API Key
So, enter your code HERE.
After this, you will get your API KEY and return to your app.
In the xml, please replace that api key with your api key.
Then export once again the app with that keystore that you made it earlier.
Now you can install the apk on your phone, and will work.
Remember, if you run from Eclipse will not work, only you need to install the app in the phone.