我告訴你我是如何解決你有同樣的問題。
首先,我清理了所有的sdk,然後我再次下載了Google Play Services lib。然後,我刪除了我的電腦的.android文件夾,並重新生成了我的debug.keystore。
之後,我只是讓我的新SHA1獲得我的Google Maps V2 Api密鑰。
更新我的apikey後,讓我們看看如何更改我的代碼。
現在我在你的xml佈局中使用MapFragment的MapFragment片段。
<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=".MapsActivity" >
<fragment
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.MapFragment" />
並使用FragmentManager找到它:
public class MapsActivity extends Activity
{
private GoogleMap map;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_map);
// Gets the MapView from the XML layout and creates it
map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
map.getUiSettings().setMyLocationButtonEnabled(false);
//map.setMyLocationEnabled(true);
map.setOnMapClickListener(this);
map.setOnMapLongClickListener(this);
try
{
MapsInitializer.initialize(MapsActivity.this);
}
catch (Exception e)
{
e.printStackTrace();
}
}
我希望這是有幫助和抱歉,如果我的英語是如此糟糕, 問候
獲得了新的api密鑰,嘗試創建新的api密鑰.... –