Pages

Wednesday, May 19, 2010

How to add a MapView Android Tab page

step1) create a keystore. in debug mode, use the system default debug.keystore on the line, if completed, to publish out, you have to create your own a keystore, and you use it to sign the project. Specific 's see the previous "Signature your android project" thing I read in post. In debug mode, we can see Eclipse the Window-> Preferences-> Android-> Build, I was in the C: \ Users \ seya \ AppData \ Local \ Android \ under debug.keystore file. This file contains the following default properties: 
Keystore name - "debug.keystore" 
Keystore password - "android" 
Key alias - "androiddebugkey" 
Key password - "android" 
CN - "CN = Android Debug, O = Android, C = US" 
Then, we use the keytool to get the MD5 fingerprint verification code in the cmd in the android sdk directory tools, using the following command: 
keytool-list-keystore C: \ Users \ seya \ AppData \ Local \ Android \ debug.keystore 
Requires a password, enter: android. Then, MD5 out: F9: 0B: EF: 70: D5: 0F: 71: A1: 62:5 F: E1: 58: C3: B9: 2B: 5C 
The string of numbers used to http://code.google.com/intl/zh-CN/android/maps-api-signup.html, enter into My certificate's MD5 fingerprint there, and then Generate API Key, the new page where to get your apiKey: 0VYn9qrD1aANK5V8UVCb0YPy76f-Ixg_roc0Fig 

Step2) Create a simple SimpleMapViewTest project. 
----- Main. Xml 
(? Xml version = "1.0" encoding = "utf-8"?> 
http://schemas.android.com/apk/res/android" 
android: orientation = "vertical" 
android: layout_width = "fill_parent" 
android: layout_height = "fill_parent" 

(View class = "com.google.android.maps.MapView" 
android: id = "@ + id / my_map" 
android: enabled = "true" 
android: apiKey = "0VYn9qrD1aANK5V8UVCb0YPy76f-Ixg_roc0Fig" 
android: layout_width = "fill_parent" 
android: layout_height = "wrap_content" 
/> 
(/ LinearLayout> 
Red areas where the use of the step1 get apiKey. 

-------- AndroidManifest. Xml 
(? Xml version = "1.0" encoding = "utf-8"?> 
(? Xml version = "1.0" encoding = "utf-8"?> 
(Manifest xmlns: android = "http://schemas.android.com/apk/res/android
package = "com.sm.test" 
android: versionCode = "1" 
android: versionName = "1.0.0"> 
(application android:icon="@drawable/icon" android:label="@string/app_name"> 
(uses-library android:name="com.google.android.maps" /> 
(Activity android: name = ". SMTest" 
android: label = "@ string / app_name"> 
(intent-filter> 
(action android:name="android.intent.action.MAIN" /> 
(category android:name="android.intent.category.LAUNCHER" /> 
(/ Intent-filter> 
(/ Activity> 
(/ Application> 
(uses-permission android:name="android.permission.INTERNET">  
(uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION">  
(uses-permission android:name="android.permission.ACCESS_FINE_LOCATION">  
(/ Manifest> 

Red is a must. 

- The code section: 
package com.sm.test; 
import com.google.android.maps.GeoPoint; 
import com.google.android.maps.MapActivity; 
import com.google.android.maps.MapController; 
import com.google.android.maps.MapView; 
import android.app.Activity; 
import android.os.Bundle; 
public class SMTest extends MapActivity ( 
/ ** Called when the activity is first created. * / 
@ Override 
public void onCreate (Bundle savedInstanceState) ( 
super.onCreate (savedInstanceState); 
setContentView (R.layout.main); 

/ / Get map view 
MapView mv = (MapView) findViewById (R.id.my_map); 
MapController controller = (MapController) mv.getController (); 

GeoPoint p = new GeoPoint ((int) (24.7 * 1000000), (int) (-238.8 * 1000000)); 
controller.animateTo (p); 
controller.setZoom (9); 


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



Thus, one run, and finally succeeded.

No comments:

Post a Comment