使用google map要这样搞。
step1)创建一个keystore.在debug模式下,使用系统默认的debug.keystore就行了,如果是完成了,要publish出去,就得自己创建一个keystore,并用它来签名你的project.具体的参见以前的《签名你的android项目》那篇帖子。在debug模式下,我们可以通过查看Eclipse的Window->Preferences->Android->Build,我的是在C:\Users\seya\AppData\Local\Android\下的debug.keystore文件。这个文件有如下默认属性:
Keystore name — "debug.keystore"
Keystore password — "android"
Key alias — "androiddebugkey"
Key password — "android"
CN — "CN=Android Debug,O=Android,C=US"
然后,我们使用keytool来获取MD5指纹验证码,在cmd中,到android sdk目录下的tools下,用如下命令:
keytool -list -keystore C:\Users\seya\AppData\Local\Android\debug.keystore
要求输入密码,输入:android. 接着,MD5出来了:F9:0B:EF:70:D5:0F:71:A1:62:5F:E1:58:C3:B9:2B:5C
用这串数字去http://code.google.com/intl/zh-CN/android/maps-api-signup.html上,输入到My certificate's MD5 fingerprint 那里,然后点Generate API Key,在新的页面里就得到了你的apiKey:0VYn9qrD1aANK5V8UVCb0YPy76f-Ixg_roc0Fig
Step2)创建一个简单的SimpleMapViewTest project.
-----main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="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>
红色地方就用到了step1里得到的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>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission>
</manifest>
红色部分是必须的。
--代码部分:
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;
}
}
这样,一运行,终于成功了。哈哈。