我按照步骤配置 Google Maps Android API v2官方步骤
我使用的是 Android 3.1 版本。我在运行项目时遇到错误。
清单文件
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.mapdemo"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
<permission
android:name="com.example.mapdemo.permission.MAPS_RECEIVE"
android:protectionLevel="signature"/>
<uses-permission android:name="com.example.mapdemo.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"/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.mapdemo.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="I paste my key as shown in picture"/>
</application>
</manifest>
MainActivity.java
package com.example.mapdemo;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@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;
}
}
Activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<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.MapFragment"/>
日志猫
01-20 15:00:18.325: E/dalvikvm(856): Could not find class 'com.google.android.gms.maps.model.LatLng', referenced from method com.google_map.MainActivity.<clinit>
01-20 15:00:18.395: E/dalvikvm(856): Could not find class 'com.google.android.gms.maps.MapFragment', referenced from method com.google_map.MainActivity.onCreate
01-20 15:00:18.565: E/AndroidRuntime(856): FATAL EXCEPTION: main
01-20 15:00:18.565: E/AndroidRuntime(856): java.lang.ExceptionInInitializerError
01-20 15:00:18.565: E/AndroidRuntime(856): at java.lang.Class.newInstanceImpl(Native Method)
01-20 15:00:18.565: E/AndroidRuntime(856): at java.lang.Class.newInstance(Class.java:1301)
01-20 15:00:18.565: E/AndroidRuntime(856): at android.app.Instrumentation.newActivity(Instrumentation.java:1022)
01-20 15:00:18.565: E/AndroidRuntime(856): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1663)
01-20 15:00:18.565: E/AndroidRuntime(856): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1764)
01-20 15:00:18.565: E/AndroidRuntime(856): at android.app.ActivityThread.access$1500(ActivityThread.java:122)
01-20 15:00:18.565: E/AndroidRuntime(856): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1002)
01-20 15:00:18.565: E/AndroidRuntime(856): at android.os.Handler.dispatchMessage(Handler.java:99)
01-20 15:00:18.565: E/AndroidRuntime(856): at android.os.Looper.loop(Looper.java:132)
01-20 15:00:18.565: E/AndroidRuntime(856): at android.app.ActivityThread.main(ActivityThread.java:4025)
01-20 15:00:18.565: E/AndroidRuntime(856): at java.lang.reflect.Method.invokeNative(Native Method)
01-20 15:00:18.565: E/AndroidRuntime(856): at java.lang.reflect.Method.invoke(Method.java:491)
01-20 15:00:18.565: E/AndroidRuntime(856): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
01-20 15:00:18.565: E/AndroidRuntime(856): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
01-20 15:00:18.565: E/AndroidRuntime(856): at dalvik.system.NativeStart.main(Native Method)
01-20 15:00:18.565: E/AndroidRuntime(856): Caused by: java.lang.NoClassDefFoundError: com.google.android.gms.maps.model.LatLng
01-20 15:00:18.565: E/AndroidRuntime(856): at com.google_map.MainActivity.<clinit>(MainActivity.java:32)
01-20 15:00:18.565: E/AndroidRuntime(856): ... 15 more
我也想知道谷歌地图 API v2的最低要求