12. android basic google map

19
12. Map Oum Saokosal Master of Engineering in Information Systems, South Korea 855-12-252-752 [email protected]

Upload: oum-saokosal

Post on 12-Jan-2017

389 views

Category:

Education


0 download

TRANSCRIPT

12. MapOum Saokosal

Master of Engineering in Information Systems, South Korea855-12-252-752

[email protected]

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 fingerprint6.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:\Users\kosal\.android\debug.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); }

@Overrideprotected boolean isRouteDisplayed() {// TODO Auto-generated method stubreturn false;}

}

• Run the App with the AVD targeting Google API

You know what, you have reached the end of this course!

Thank You Very MuchGood Luck!

From Prof. Oum SaokosalOn Feb 1, 2012