12. Map
Oum Saokosal
Master of Engineering in Information Systems, South Korea
855-12-252-752
oum_saokosal@yahoo.com
Map
• Google owns Android, so it is obvious that
the map you're going to use in Android
app must be Google Map.
• However to use Google Map in your app
is not as easy as it should be.
Instruction how to make Map app:
1. Go to window menu -> Android SDK Manager
-> Download Google API (2.3.3 API 10)
2. Create AVD Targeting
Google API:
For this map app, you
need to create an AVD
targeting Google API. In
this case, please choose
API level 10 for 2.3.3.
3. Android Manifest: Add Google Maps Library
<application …>
<uses-library android:name="com.google.android.maps" />
<activity…>
...
</application>
4. Android Manifest: Add Internet Permission
<manifest …>
<uses-sdk android:minSdkVersion="10" />
<uses-permission
android:name="android.permission.INTERNET"/>
...
...
</manifest>
AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.kosalab"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="10" />
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<uses-library android:name="com.google.android.maps" />
<activity
android:label="@string/app_name"
android:name=".GoogleMapActivity" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
5. main.xml: replace with this codes
<?xml version="1.0" encoding="utf-8"?>
<com.google.android.maps.MapView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mymap"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="true"
android:apiKey="Enter Your API Key"
/>
6. Getting API Key:
6.1. Go to a website, http://code.google.com/android/add-
ons/google-apis
6.2. Click on Maps API Key Signup
6.3. Enter your MD5 fingerprint. (Scroll down a bit)
6.4. To get MD5 fingerprint
6.4.1. In Eclipse, go to Window -> Preferences -> Android ->
Build -> Default debug keystore -> Copy the path
6.4.2. In Windows Explorer, go to Java installed
folder, e.g. c:Program Files (x86)Java -> jre6 ->
bin -> keystore.exe
• 6.4.3. After you found out keystore.exe, open
cmd, and then go to folder where keystore
located.
• 6.4.4. Type a command line
keytool -list -alias androiddebugkey -keystore
"C:Userskosal.androiddebug.keystore" -storepass
android -keypass android
-> Copy the PrivateKey
• 6.4.5. Paste the PrivateKey into MD5 Fingerprint
in the website -> Click "Generate API Key"
6.4.6. Finally, you will get your API key:
7. Enter the API key into main.xml.
<?xml version="1.0" encoding="utf-8"?>
<com.google.android.maps.MapView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mymap"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="true"
android:apiKey="eNtEr_y0uR_Ap1_kEy_HeRe"
/>
8. In Java, you must extends MapActivity instead of Activity:
package com.kosalab;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;
import android.os.Bundle;
public class GoogleMapActivity extends MapActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
MapView mapView = (MapView) findViewById(R.id.mymap);
mapView.setBuiltInZoomControls(true);
}
@Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}
}
• Run the App with the AVD targeting Google API
You know what, you have
reached the end of this course!
Thank You Very Much
Good Luck!
From Prof. Oum Saokosal
On Feb 1, 2012

12. Android Basic Google Map

  • 1.
    12. Map Oum Saokosal Masterof Engineering in Information Systems, South Korea 855-12-252-752 oum_saokosal@yahoo.com
  • 2.
    Map • Google ownsAndroid, so it is obvious that the map you're going to use in Android app must be Google Map. • However to use Google Map in your app is not as easy as it should be.
  • 3.
    Instruction how tomake Map app: 1. Go to window menu -> Android SDK Manager -> Download Google API (2.3.3 API 10)
  • 4.
    2. Create AVDTargeting Google API: For this map app, you need to create an AVD targeting Google API. In this case, please choose API level 10 for 2.3.3.
  • 5.
    3. Android Manifest:Add Google Maps Library <application …> <uses-library android:name="com.google.android.maps" /> <activity…> ... </application> 4. Android Manifest: Add Internet Permission <manifest …> <uses-sdk android:minSdkVersion="10" /> <uses-permission android:name="android.permission.INTERNET"/> ... ... </manifest>
  • 6.
    AndroidManifest.xml: <?xml version="1.0" encoding="utf-8"?> <manifestxmlns:android="http://schemas.android.com/apk/res/android" package="com.kosalab" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="10" /> <uses-permission android:name="android.permission.INTERNET"/> <application android:icon="@drawable/ic_launcher" android:label="@string/app_name" > <uses-library android:name="com.google.android.maps" /> <activity android:label="@string/app_name" android:name=".GoogleMapActivity" > <intent-filter > <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest>
  • 7.
    5. main.xml: replacewith this codes <?xml version="1.0" encoding="utf-8"?> <com.google.android.maps.MapView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/mymap" android:layout_width="fill_parent" android:layout_height="fill_parent" android:clickable="true" android:apiKey="Enter Your API Key" />
  • 8.
    6. Getting APIKey: 6.1. Go to a website, http://code.google.com/android/add- ons/google-apis 6.2. Click on Maps API Key Signup
  • 9.
    6.3. Enter yourMD5 fingerprint. (Scroll down a bit)
  • 10.
    6.4. To getMD5 fingerprint 6.4.1. In Eclipse, go to Window -> Preferences -> Android -> Build -> Default debug keystore -> Copy the path
  • 11.
    6.4.2. In WindowsExplorer, go to Java installed folder, e.g. c:Program Files (x86)Java -> jre6 -> bin -> keystore.exe
  • 12.
    • 6.4.3. Afteryou found out keystore.exe, open cmd, and then go to folder where keystore located.
  • 13.
    • 6.4.4. Typea command line keytool -list -alias androiddebugkey -keystore "C:Userskosal.androiddebug.keystore" -storepass android -keypass android -> Copy the PrivateKey
  • 14.
    • 6.4.5. Pastethe PrivateKey into MD5 Fingerprint in the website -> Click "Generate API Key"
  • 15.
    6.4.6. Finally, youwill get your API key:
  • 16.
    7. Enter theAPI key into main.xml. <?xml version="1.0" encoding="utf-8"?> <com.google.android.maps.MapView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/mymap" android:layout_width="fill_parent" android:layout_height="fill_parent" android:clickable="true" android:apiKey="eNtEr_y0uR_Ap1_kEy_HeRe" />
  • 17.
    8. In Java,you must extends MapActivity instead of Activity: package com.kosalab; import com.google.android.maps.MapActivity; import com.google.android.maps.MapView; import android.os.Bundle; public class GoogleMapActivity extends MapActivity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); MapView mapView = (MapView) findViewById(R.id.mymap); mapView.setBuiltInZoomControls(true); } @Override protected boolean isRouteDisplayed() { // TODO Auto-generated method stub return false; } }
  • 18.
    • Run theApp with the AVD targeting Google API
  • 19.
    You know what,you have reached the end of this course! Thank You Very Much Good Luck! From Prof. Oum Saokosal On Feb 1, 2012