谷歌地图Android的API V2抛出GooglePlayServicesNotAvailableException的,过时的,SupportMapFragment.getMap()返回null [英] Google Maps Android API v2 throws GooglePlayServicesNotAvailableException, out of date, SupportMapFragment.getMap() returns null

本文介绍了谷歌地图Android的API V2抛出GooglePlayServicesNotAvailableException的,过时的,SupportMapFragment.getMap()返回null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想,以纳入新的谷歌地图的Andr​​oid API v2转换成使用Android支持库的应用程序。 我已经经历了很多次迭代去尝试得到的地方工作,现在我已经放弃了,我想我应该在这里问。

I am trying to incorporate the new Google Maps Android API v2 into an application using the Android Support Library. I've gone through many iteration to try to get somewhere to work and now I have given up and thought I should ask here.

我去了API控制台,创建了一个项目,使谷歌地图API V2的Andr​​ oid,根据需要创建一个调试KEY,贴在清单中。没有身份验证问题或类似的东西。 pretty的肯定,我这样做是正确的。

I went to the API Console, created a project, enabled Google Maps API v2 for Android, created a debug KEY as required and pasted it on the manifest. No authentication problems or anything like that. Pretty sure I did this right.

在我的项目的文件夹,我把 Android的支持 - v4.jar (通过项目右键点击 - > Android->添加支持库...)。在Eclipse我做文件 - >导入 - > Android->现有的Andr​​oid code进入工作区和进口Android的SDK /谷歌/ google_play_services / libproject /谷歌播放services_lib的最新(修订版3)。然后,我增加一条,作为一个依赖库到我的项目(​​项目右键单击 - >属性 - > Android->添加它作为底库的依赖。

In my project's libs folder I put android-support-v4.jar (via project right-click->Android->Add Support Library...). In Eclipse I did File->Import->Android->Existing Android Code Into Workspace and imported the latest (rev 3) of android-sdk/google/google_play_services/libproject/google-play-services_lib. Then I added it as a dependency library to my project (project right-click->Properties->Android->Add it as a library dependency on the bottom.

在我的表现,我有:

<manifest xmlns:android="http://schemas.android.com/apk/res/android" ...>
    <permission
      android:name="myapp.permission.MAPS_RECEIVE"
      android:protectionLevel="signature"/>

    <All the uses-permission required like INTERNET, ACCESS_NETWORK_STATE, WRITE_EXTERNAL_STORAGE, FINE AND COARSE LOCATION, etc>
    <uses-permission android:name="myapp.permission.MAPS_RECEIVE"/>
    <uses-feature android:glEsVersion="0x00020000" android:required="true"/>
    <application ...>
        ...
        <uses-library android:name="com.google.android.maps" />
        <meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="AI..."/>
    </application>

在我mainview.xml我有:

In my mainview.xml I have:

<fragment
   xmlns:android="http://schemas.android.com/apk/res/android"
   android:id="@+id/map"
   android:layout_width="fill_parent"
   android:layout_height="fill_parent"
   class="com.google.android.gms.maps.SupportMapFragment" />

现在的MainView.java我有:

Now on MainView.java I have:

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;

public class MainView extends FragmentActivity ... {
    private GoogleMap mMap;

    @Override
    protected void onResume() {
        ...
        Fragment fragment = getSupportFragmentManager().findFragmentById(R.id.map);
        SupportMapFragment mapFragment = (SupportMapFragment)fragment;
        mMap = mapFragment.getMap();
        //PROBLEM: mMap is null here even though mapFragment is not
    }
}

后来我想我可能需要初始化,所以我说,在我的片段的onCreate 设置内容视图后:

//Fragments
FragmentManager manager = getSupportFragmentManager(); 
FragmentTransaction transaction = manager.beginTransaction();
transaction.add(R.id.map, SupportMapFragment.newInstance());
transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
transaction.commit();

然后我说,也许这不是 SupportMapFragment ,但我其实应该是指实际的片段,并在我的 onResume 我所做的:

Then I said, maybe it's not SupportMapFragment but I actually should refer to the actual fragment, and in my onResume I did:

Fragment fragment = getSupportFragmentManager().findFragmentById(R.id.map);
SupportMapFragment mapFragment = (SupportMapFragment)fragment;

//Fragments
FragmentManager manager = getSupportFragmentManager(); 
FragmentTransaction transaction = manager.beginTransaction();
transaction.add(R.id.map, mapFragment);
transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
transaction.commit();

mMap = mapFragment.getMap();

MMAP 又是空在此之后。

然后,我看到有一个 MapsInitializer 类,所以我想,也许我应该称之为第一。

Then I saw there is a MapsInitializer class, so I thought maybe I should call that first.

于是我加了code得到的片段在上面code面前:

So I added the code before getting the fragment in the above code:

try {
    MapsInitializer.initialize(this);
} catch (GooglePlayServicesNotAvailableException e) {
    e.printStackTrace();
}

通过这个报告的logcat警告(行313是 MapsInitializer.initialize(本)):

With this Logcat reported the warning (line 313 is the MapsInitializer.initialize(this)):

com.google.android.gms.common.GooglePlayServicesNotAvailableException
    at com.google.android.gms.internal.n.c(Unknown Source)
    at com.google.android.gms.internal.n.a(Unknown Source)
    at com.google.android.gms.maps.MapsInitializer.initialize(Unknown Source)
    at myapp.activities.MainView.inflateSelectedViewAndSetData(MainView.java:313)
    at myapp.activities.MainView.onClick(MainView.java:642)
    at android.view.View.performClick(View.java:3153)
    at android.view.View$PerformClick.run(View.java:12148)
    at android.os.Handler.handleCallback(Handler.java:587)
    at android.os.Handler.dispatchMessage(Handler.java:92)
    at android.os.Looper.loop(Looper.java:152)
    at android.app.ActivityThread.main(ActivityThread.java:4615)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:491)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
    at dalvik.system.NativeStart.main(Native Method)

在我尝试的logcat将报告以下警告:

Throughout my attempts Logcat would report the following warning:

Google Play services out of date.  Requires 2010100 but found 1013

这可能是一个/罪魁祸首,但我发现没有办法了。

This could be a/the culprit but I found no solution.

在这一点上,我的想法。我看了几个线程<一href="http://stackoverflow.com/questions/13696620/google-maps-android-api-v2-authorization-failure">here, <一href="http://stackoverflow.com/questions/13691943/this-app-wont-run-unless-you-update-google-play-services-via-bazaar">here, 这里但没有建议解决了这个问题。关于后者,他们建议不包括项目的依赖,只是包括jar文件。好了,没有工作或者使用任何谷歌播放services.jar 谷歌播放services_lib /库文件夹或从该项目中导出自己的罐子。

At this point I am out of ideas. I read several threads here, here, here but none of the suggestions resolved the problem. On the latter they suggest not including the project dependency and just including the jar file. Well, that did not work either using either google-play-services.jar from the google-play-services_lib/libs folder or exporting my own jar from that project.

通过我的实际设备(2.3.5和3.2平板电脑)上运行的方式,而不是仿真器。

By the way I am running on an actual device (2.3.5 and a tablet with 3.2), not the emulator.

任何帮助,竭诚AP preciated。 :)

Any help wholeheartedly appreciated. :)

更新:

的解决方案是由下面量子位

The solution is below by qubit.

据导出库的依赖,一种巧妙的方法不必处理它(这是在与库处理一个痛苦)是使用 FatJar 并导出 google_play_services_lib 项目(我并没有因为当它更新我不想重新导入创建一个本地副本),并包括在您的项目作为另一个jar文件塔输出脂肪jar文件。 注:选择在脂肪罐子中包含哪些jar文件,我必须排除 annotations.jar 文件,因为它已经是pre-包含并导致错误对于重复。 现在我需要做的是包括 google_play_services_rev_3.jar 在我的项目的文件夹,我好去。

As far exporting the library dependency, a neat way to not have to deal with it (which is a pain when dealing with repositories) is to use FatJar and export the google_play_services_lib project (which I DID NOT create a local copy from because when it updates I don't want to re-import), and include tha output fat jar file in your project as another jar file. NOTE: When choosing which jar files to include in the fat jar, I had to exclude the annotations.jar file as it was already pre-included and was causing errors for duplication. Now all I have to do is include the google_play_services_rev_3.jar in my project's libs folder and I am good to go.

推荐答案

下载,然后从Play商店安装最新的谷歌播放服务。出于某种原因,我无法找到它通过搜索。通过运行在该文件夹的SDK中的示例应用程序 /演员/谷歌/ google_play_services /样本/图我被提示安装升级,被送到Play商店做这一点。

Download and install the latest Google Play services from the Play Store. For some reason, I couldn't find it by searching. By running the sample app from the SDK in the folder /extras/google/google_play_services/samples/maps I was prompted to install the upgrade and was taken to the Play Store to do that.

这篇关于谷歌地图Android的API V2抛出GooglePlayServicesNotAvailableException的,过时的,SupportMapFragment.getMap()返回null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆