2010年1月7日 星期四

Android Google Map開發注意事項

1. GoogleMap for Android 在res/layout/main.xml佈局的com.google.android.maps.MapView的tag里需要的一個android:apiKey
com.google.android.maps.mapview
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:apiKey=""
用keytool產生一個keystore
keytool -genkey -v -keystore [keystore名稱] -alias [密鎖別名] -keyalg [加密算法] -validity [密鎖的有效期, 以天數計算]
加密算法可有DSA或RSA選擇
如keytool -genkey -v -keystore abc.keystore -alias mydog -keyalg RSA -validity 10000
輸入密碼, 用戶等信息之後會生成一個abc.keystore的檔案

2. 申請MapView需要的apikey
這里需要你輸入一個MD5 fingerprint
用第一步產生的keystore可得到這個MD5 fingerprint
keytool -list -alias [密鎖別名] -keystore [keystore名稱]
如keytool -list -alias mydog -keystore abc.keystore
顯示器會顯示如下:
輸入 keystore 密碼:
abcd, 2010/1/7, PrivateKeyEntry,
認證指紋 (MD5): 94:1D:16:69:9C:90:C3:96:CD:DE:F7:6E:CF:C2:D8:95
把這個MD5填入瀏覽器, 按Genearte
就會得到一個api key
0_5g26-vl_LyA8vTyfi1IWgEWzMWEEjCgfZmgbA
把這個api key 填入layout的com.google.android.maps.MapView
com.google.android.maps.mapview
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:apiKey="0_5g26-vl_LyA8vTyfi1IWgEWzMWEEjCgfZmgbA"

3. AndroidManifest.xml
需要在AndroidManifest.xml加入
uses-library name="com.google.android.maps"
uses-permission name="android.permission.INTERNET"

沒有留言:

張貼留言