好的,所以我通过创建一个批处理文件获得了我的 SHA1 指纹。之后,我转到“服务”页面并启用 Google Maps API v2 和 v3。我还去了“API 访问”页面并使用 SHA1;PACKAGENAME 创建了一个新的 Android 密钥。在此之后,我转到我的项目文件夹并添加以下代码:
<permission
android:name = "com.example.test.permission.MAPS_RECEIVE"
android:protectionLevel = "signature"
/>
<uses-feature
android:glEsVersion = "0x00020000"
android:required = "true"
/>
<uses-permission android:name="com.example.test.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-library android:name="com.google.android.maps" />
<meta-data
android:name = "com.google.android.maps.v2.API_KEY"
android:value = "APIKEY"
/>
我还创建了一个 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/mapview_MV"
android:layout_width = "fill_parent"
android:layout_height = "fill_parent"
android:clickable = "true"
android:apiKey = "APIKEY"
/>
在我的 HTC One X+ 上编译并运行该项目后,我只看到一堆灰色瓷砖。我还尝试在代码中使用 MapView,如下所示:
/********************************************************************
* ONCREATE *
********************************************************************/
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView( R.layout.general_layout );
MapView mapView = new MapView( GamePage.this, "APIKEY" );
MapController mc = mapView.getController();
String coordinates[] = {"1.352566007", "103.78921587"};
double lat = Double.parseDouble(coordinates[0]);
double lng = Double.parseDouble(coordinates[1]);
GeoPoint p = new GeoPoint( (int) (lat * 1E6), (int) (lng * 1E6) );
mc.animateTo(p);
mc.setZoom(17);
FrameLayout fl = ( FrameLayout ) findViewById(R.id.general_frameHolder_FL);
fl.addView(mapView);
}
我看到以下错误:
Couldn't get connection factory client
谁能告诉我我到底做错了什么!?