我做了所有的步驟,我添加谷歌播放服務到我的項目,我什麼都做。我不是什麼問題。我創建我的api密鑰使用調試證書指紋在eclipse窗口中使用SHA1
指紋> preferences> android;我使用的是LG E400 CON的Android 2.3.6MapView谷歌地圖api V2看起來空白只顯示網格+/-按鈕
MainActivity:
import android.os.Bundle;
import android.app.Activity;
import com.google.android.gms.common.GooglePlayServicesUtil;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapView;
import com.google.android.gms.maps.MapsInitializer;
public class MainActivity extends Activity {
GoogleMap map;
MapView m;
com.google.android.gms.maps.Projection projection;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
m=(MapView) findViewById(R.id.mapview);
m.onCreate(savedInstanceState);
map = m.getMap();
if (map != null) {
// The Map is verified. It is now safe to manipulate the map.
}else{
// check if google play service in the device is not available or out-dated.
GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
// nothing anymore, cuz android will take care of the rest (to remind user to update google play service).
}
try{map.getUiSettings().setMyLocationButtonEnabled(false);
map.setMyLocationEnabled(true);
}catch(Exception ex){ex.printStackTrace();}
MapsInitializer.initialize(this);
}
@Override
public void onResume() {
super.onResume();
m.onResume();
}
@Override
public void onDestroy() {
super.onDestroy();
m.onDestroy();
}
@Override
public void onLowMemory() {
super.onLowMemory();
m.onLowMemory();
}
@Override
public void onSaveInstanceState(Bundle outState){
super.onSaveInstanceState(outState);
m.onSaveInstanceState(outState);
}
}
佈局:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<com.google.android.gms.maps.MapView
android:id="@+id/mapview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
</RelativeLayout>
清單:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.voicesee"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="9"
android:targetSdkVersion="15" />
<permission
android:name="com.example.voicesee.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="com.example.voicesee.permission.MAPS_RECEIVE" />
<!-- Copied from Google Maps Library/AndroidManifest.xml. -->
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<!-- The following two permissions are not required to use
Google Maps Android API v2, but are recommended. -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<activity
android:name="com.example.voicesee.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyAguDjIFiVWi18ll7Yh0oa8C7hWju1PUzI"/>
</application>
感謝您的幫助!
謝謝!!我閱讀鏈接頁面中的答案! – user3338328