我也遇到过同样的问题,我正确地按照步骤操作并能够解决这个问题
首先(从 Google Developer 控制台设置您的项目)
Go to API 控制台 - Google 代码 https://code.google.com/apis/console/
Create A project As shown in the images
单击“创建”,然后您将要求添加项目名称,如图所示
once you create your project its time to select what service we need to use,In this case we need android v2 map so select the Google Maps Android API v2 from Service As shown,
Now go to Api Access and create your OAuth 2.0 .By provide your package name and SHA1 fingerprint in the corresponding fields.
once you finish with OAuth 2.0 we are ready to use your API Key
Now Create An Android project with the same package name used while creating the OAuth 2.0. and Check whether you have the google play service in Android SDK Manager otherwise install google play service.
After installing Google playservice you will find a Google play library in Your Android YourSdkpath\extras\google\google_play_services.Import that project to your workspace and give it as the refrence library to your project
之后将相应的java和xml文件放入您的项目中。
MainActivity.java
package yourpackage;//Package name used while creating the Api key
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesUtil;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
import android.os.Bundle;
import android.app.Activity;
import android.app.Dialog;
import android.support.v4.app.FragmentActivity;
import android.view.Menu;
public class MainActivity extends FragmentActivity {
GoogleMap googleMap;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Getting status
int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getBaseContext());
// Showing status
if(status==ConnectionResult.SUCCESS)
{
SupportMapFragment supportMapFragment = (SupportMapFragment)
getSupportFragmentManager().findFragmentById(R.id.map);
// Getting a reference to the map
googleMap = supportMapFragment.getMap();
}
else{
int requestCode = 10;
Dialog dialog = GooglePlayServicesUtil.getErrorDialog(status, this, requestCode);
dialog.show();
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}
活动_main.xml
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="wrap_content"
android:layout_height="match_parent" />
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="yourpackage"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="16" />
<permission
android:name="yourpackage.permission.MAPS_RECEIVE"
android:protectionLevel="signature"/>
<uses-permission android:name="yourpackage.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-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" >
<activity
android:name="yourpackage.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="YourAPIkey"/>
希望它能帮助你