今天我嘗試使用谷歌地圖API V2爲Android 2.3.3 我的步驟:的Android 2.3和谷歌地圖API V2
- 接到debug.keystore
- SHA1代碼創建谷歌新項目API控制檯
- 註冊新的ID
- 啓用谷歌地圖的Android API V2
- 作爲輸入SHA1創建Android鍵; it.mappe(it.mappe是我 包)
- 獲取API密鑰
- 更新AndroidManifest文件:
<uses-permission android:name="it.mappe.permission.MAPS_RECEIVE" />
<uses-sdk android:minSdkVersion="10" android:targetSdkVersion="16" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<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="MY_KEY" />
<activity
android:name="it.mappe.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>
</application>
我的主要活動
public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main);
}
我activity_main:
片段的xmlns:安卓= 「http://schemas.android.com/apk/res/android」 機器人:ID =「@ + ID /地圖」 機器人:layout_width = 「match_parent」 機器人:layout_height = 「match_parent」 類= 「com.google.android.gms.maps.SupportMapFragment」/>
複製目錄ANDROID_SDK_DIR /演員/谷歌/ google_play_services/libproject /克oogle賞玩services_lib到項目的根
添加/extras/android/compatibility/v4/android-support-v4.jar作爲 外部JAR
在下一行添加到YOUR_PROJECT /項目。性能 android.library.reference.1 =的Google Play-services_lib
,當我在我的三星Galaxy S運行(與谷歌發揮服務APK),它crashs和logcat中顯示了這種錯誤
E/AndroidRuntime(6435): FATAL EXCEPTION: main java.lang.RuntimeException: Unable to start activity ComponentInfo{it.mappe/it.mappe.MainActivity}:
android.view.InflateException: Binary XML file line #2: Error inflating class fragment
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
at android.app.ActivityThread.access$1500(ActivityThread.java:117)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:3687)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class fragment
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:581)
at android.view.LayoutInflater.inflate(LayoutInflater.java:386)
at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:209)
at android.app.Activity.setContentView(Activity.java:1657)
at it.mappe.MainActivity.onCreate(MainActivity.java:12)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
... 11 more
Caused by: java.lang.ClassNotFoundException: android.view.fragment in loader dalvik.system.PathClassLoader[/data/app/it.mappe-2.apk]
at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at android.view.LayoutInflater.createView(LayoutInflater.java:471)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:549)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:66)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:568)
... 19 more
一些建議?
編輯
這裏我的main.xml:
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment"/>
請發佈'main.xml'的實際內容 – CommonsWare
你可以看到它,在編輯:) – antedesk
是否能夠在Android模擬器中運行谷歌地圖V2? – Sripaul