Android on Eclipse 101: Google MapView

In order to get MapView, you will need to first have your application target Google API 1.5. Then you would abtain a google maps API for your android application:

1.  Generating MD5 Fingerprint of the SDK Debug Certificate . This is under Windows XP:

cd C:\Program Files\Java\jdk1.6.0_13\bin
keytool -list -alias androiddebugkey -keystore “C:\Documents and Settings\username\.android\debug.keystore” -storepass android -keypass android
I got something like:
androiddebugkey, May 18, 2009, PrivateKeyEntry,
Certificate fingerprint (MD5): 94:1E:43:49:87:73:BB:E6:A6:88:D7:20:F1:8E:B5:98
Then I go to here:
http://code.google.com/intl/ja/android/maps-api-signup.html
to get the api key.
2. Now you can get the map view up and running. The catch is that it  seems that you need to use/subclass MapActivity in order to use a MapView. The MapView could be mixed up with other views (not necessarily need to be the top node in your view layout). Also you need to declare in your manifest.xaml that you are using google map and internet permission. For example:

<!–Manifest xml–>
<?xml version=”1.0″ encoding=”utf-8″?>
<manifest xmlns:android=”http://schemas.android.com/apk/res/android&#8221;
package=”com.maohao.android.test”
android:versionCode=”1″
android:versionName=”1.0″>
<uses-sdk android:minSdkVersion=”4″
android:targetSdkVersion=”4″ />
<application android:icon=”@drawable/icon” android:label=”@string/app_name”>
<activity android:label=”@string/app_name” android:name=”MyTestMain”>
<intent-filter>
<action android:name=”android.intent.action.MAIN” />
<category android:name=”android.intent.category.LAUNCHER” />
</intent-filter>
</activity>
<activity android:name=”.googlemaptest.MapTest1″></activity>
<uses-library android:name=”com.google.android.maps” />
</application><uses-permission android:name=”android.permission.INTERNET” />
</manifest>

<!–/res/layout/main.xml–>
<?xml version=”1.0″ encoding=”utf-8″?>
<FrameLayout
xmlns:android=”http://schemas.android.com/apk/res/android&#8221;
android:id=”@+id/container”
android:layout_width=”match_parent”
android:layout_height=”match_parent”>

<WebView
android:id=”@+id/webview”
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:clickable=”true”
android:apiKey=”0P-lFg3oLM1s4ffK1LiMkkFi9dJ4mFvCcd8oELA”
/>
</FrameLayout>

package com.maohao.android.test.googlemaptest;
//import relavent classes
//,..
public class MapTest1 extends MapActivity {

WebView mWebView;
MapView mMapView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.flipview_main1);

mWebView = (WebView) findViewById(R.id.webview);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.loadUrl(“http://www.google.com&#8221;);

mMapView = (MapView) findViewById(R.id.mapview);

}
@Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: