android - 无法解析符号 'OnMapReadyCallback' 问题

标签 android google-maps android-manifest

我正在关注 Google Maps Android“入门”教程- https://developers.google.com/maps/documentation/android/

但我遇到了一个错误“”无法解析符号'OnMapReadyCallback',这可能是一个简单的修复方法,但让我感到困惑。这是我为应用程序导入语句的代码:

import android.app.Activity;
import android.support.v4.app.FragmentActivity;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.os.Bundle;
import android.support.v4.app.ActionBarDrawerToggle;
import android.support.v4.widget.DrawerLayout;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class main extends FragmentActivity implements OnMapReadyCallback {


    // Within which the entire activity is enclosed
    DrawerLayout mDrawerLayout;

    // ListView represents Navigation Drawer
    ListView mDrawerList;

    // ActionBarDrawerToggle indicates the presence of Navigation Drawer in the action bar
    ActionBarDrawerToggle mDrawerToggle;

    // Title of the action bar
    String mTitle="";

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

Android list :

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="temp.com.temp"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="14"
        android:targetSdkVersion="19" />
    <uses-permission android:name="android.permission.INTERNET"/>

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >




        <activity android:name="temp.com.temp.Login"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".main"
            android:label="@string/app_name" >
        </activity>

        <activity
            android:name="temp.com.temp.Register"
            android:label="@string/app_name"  >
        </activity>

        <meta-data
            android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version" />
        <meta-data
            android:name="com.google.android.maps.v2.API_KEY"
            android:value="AIzaSyBCCBIgQMw3XgIK4eQHndGHHlzvcT7vgwQ"/>
    </application>
    <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"/>
    <!-- The following two permissions are not required to use
         Google Maps Android API v2, but are recommended. -->
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
    <uses-feature
        android:glEsVersion="0x00020000"
        android:required="true"/>
</manifest>

主布局文件:

<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- The main content view -->
<FrameLayout
    android:id="@+id/content_frame"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />
<!-- Google Maps -->
    <fragment xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/map"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:name="com.google.android.gms.maps.MapFragment"/>
<!-- The navigation drawer -->
<ListView android:id="@+id/drawer_list"
    android:layout_width="240dp"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:choiceMode="singleChoice"
    android:divider="@android:color/transparent"
    android:dividerHeight="0dp"
    android:background="#111"/>
</android.support.v4.widget.DrawerLayout>

最佳答案

OnMapReadyCallback 刚刚在 Maps V2 SDK 的最新更新中出现。如果需要,您需要升级到该 SDK 的足够新版本。

Android Studio 用户可以从 the new Play Services granular dependencies 切换到 compile 'com.google.android.gms:play-services-maps:6.5.87' , 以获得这个新类并可能减少他们的 APK 的大小作为附带好处。

关于android - 无法解析符号 'OnMapReadyCallback' 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27527783/

相关文章:

android - 如何在 android TextView 中显示 html 特殊字符

reactjs - react Jest 测试。无法使用 google js api 读取未定义的属性 'maps'

android - getLastKnownLocation() 始终返回相同的位置,即使在移动设备后也是如此

javascript - Google map 标记 - 信息窗口需要删除该标记

java - developer.android.com - 我的第一个应用程序/ Hello World

flutter - AndroidManifest.xml 中有多个未解析的类。使用 shared_intent 插件 MissingPluginException 时出错

android - 如何使用 React Native Share API 共享 App 链接?

android - 使用 Dagger 时 2 : e: [kapt] An exception occurred: java. lang.IllegalArgumentException: void

android - Android 上的袖珍狮身人面像

android - 是否可以在 AndroidManifest.xml 标签中有自定义属性?