MapView类 - Android电子 [英] MapView - Android

本文介绍了MapView类 - Android电子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我试图添加到MapView类的LinearLayout这是我的code;

Hello i'm trying to add mapview to linearlayout this is my code;

         GoogleMap mMap = mMapView.getMap();  
         if (mMap != null ) {

             CameraUpdate cameraUpdate= CameraUpdateFactory.newLatLngZoom(new LatLng(-33.87365, 151.20689), 10);
         if(cameraUpdate!=null)
             mMap.moveCamera(cameraUpdate);
             setUpMap(mMap);
         } 

<一个href=\"https://developers.google.com/maps/documentation/android/reference/com/google/android/gms/maps/CameraUpdateFactory\"相对=nofollow> documantation 说;等待的GoogleMap变得可用,您已经添加到您的应用程序MapFragment或图形页面。您可以验证的GoogleMap的可调用的GetMap()方法,并检查返回的对象不为空。

但我仍然得到的显示java.lang.NullPointerException:CameraUpdateFactory没有初始化的。有没有什么办法来检查cameraUpdateFactory准备好了吗?

documantation says; Wait for a GoogleMap to become available from a MapFragment or MapView that you have added to your application. You can verify that the GoogleMap is available by calling the getMap() method and checking that the returned object is not null.

But i still get "java.lang.NullPointerException: CameraUpdateFactory is not initialized". is there any way to check cameraUpdateFactory is ready?

推荐答案

您可以强制初始化具有以下code

You can force an initialization with the following code

    try {
        MapsInitializer.initialize(context);
    } catch (GooglePlayServicesNotAvailableException impossible) {
        /* Impossible */
    }

将这个片段在的onCreate 方法顶端,它应该工作。

Place this snippet in your onCreate method to the top and it should work.

这篇关于MapView类 - Android电子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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