我试图使用Map Api v2几天但没有取得任何成功。这是我的代码:
我的HelloGoogleActivity.java:
package com.example.hellogooglemap;
import android.os.Bundle;
import com.google.android.maps.MapActivity;
public class HelloGoogleActivity extends MapActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fragment_hello_google);
}
@Override
protected boolean isRouteDisplayed() {
return false;
}
}
我的HelloGoogleMap.Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.hellogooglemap"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="19" />
<permission
android:name="com.example.hellogooglemap.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="com.example.hellogooglemap.permission.MAPS_RECEIVE" />
<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" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<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.maps.v2.API_KEY"
android:value="XXXXXyCWfP6QJkMxpQjITsn3IVYT1J_t8UxMohU" />
<uses-library android:name="com.google.android.maps" />
<activity
android:name="com.example.hellogooglemap.HelloGoogleActivity"
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>
我的fragment_hello_google.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<com.google.android.maps.MapView
android:id="@+id/mapView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:apiKey="AIzaSyCWfP6QJkMxpQjITsn3IVYT1J_t8UxMohU"
android:clickable="true"
android:enabled="true" />
我的activity_hello_google.xml:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.hellogooglemap.HelloGoogleActivity"
tools:ignore="MergeRootFrame" />
当我运行此应用程序时,我得到一张如下空白地图:http://i.stack.imgur.com/B7H4G.jpg
我几次检查了我的apiKey。
那我该怎么办?
答案 0 :(得分:0)
如果您使用的是MapView,则需要在onCreate()
方法或onResume()
中实现此功能。
MapsInitializer.initialize(Activity);
yourMapView.onCreate(savedInstanceState);