5

我按照步骤配置 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>

API 密钥 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的最低要求

4

3 回答 3

1

您应该尝试在本指南中导入 google play 库

于 2013-01-20T12:27:10.370 回答
1

首先安装 Google play 服务,如果您使用的是 Android 2.2,请使用此代码

public class MainActivity extends FragmentActivity {    
    @Override
     protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);    
        SupportMapFragment fragment = new SupportMapFragment();
        getSupportFragmentManager().beginTransaction().add(android.R.id.content, fragment).commit();
    }    
    @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;
    }
}
于 2013-08-12T17:59:09.740 回答
0

我遇到了类似的问题,我通过以下方案步骤解决了该问题:

-1- 我下载了最新的 ADT(Windows 64 位版本 23.0.3)以安装 Google Play 服务 API。

-2-问题仍然存在,在此链接中尝试了@user3469294 答案。

ADT 64 位版本有问题,在使用SupportMapFragment(不断崩溃)、下载 32 位 ADT 并在其 SDK 上安装 google play services API 然后使用它的库时解决了我的问题

于 2014-09-05T19:57:23.960 回答