将GroundOverlay添加到gMap

时间:2016-09-11 19:59:29

标签: java android google-maps

我正在开发一个室内导航项目,需要在建筑物的平面图中添加一个groundOverlay。我遵循了Google开发者网站上的文档指南。但是当我尝试将叠加层添加到地图时,它会给我NullPointerException。 继承我的代码:

@Override
public void onMapReady(GoogleMap googleMap) {
    mMap = googleMap;

    mMap.setIndoorEnabled(true);
    mMap.setOnIndoorStateChangeListener(this);
    mMap.setPadding(0,0,50,0);
    mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(-28.666957, -55.994823), 19));

    //add mapOverlay
    LatLngBounds iffBounds = new LatLngBounds(
            new LatLng(-28.667177,-55.995104),
            new LatLng(-28.667061,-55.994443)
    );
    GroundOverlayOptions iffMap = new GroundOverlayOptions()
            .image(BitmapDescriptorFactory.fromResource(R.raw.piso_1))
            .positionFromBounds(iffBounds);


    mapOverlay = mMap.addGroundOverlay(iffMap);
}

我已经尝试了对代码进行debbuging,我看不出有什么问题,所有内容都被正确实例化,但是当它执行最后一行时

mapOverlay = mMap.addGroundOverlay(iffmap);

我的应用崩溃了。

这是来自logCat的StackTrace:

E/AndroidRuntime: FATAL EXCEPTION: main
              Process: br.com.imerljak.vegvisir, PID: 2390
              java.lang.NullPointerException: null reference
                  at maps.w.c.a(Unknown Source)
                  at maps.ad.g$a.<init>(Unknown Source)
                  at maps.ad.g.a(Unknown Source)
                  at maps.ad.w.<init>(Unknown Source)
                  at maps.ad.u.a(Unknown Source)
                  at vo.onTransact(:com.google.android.gms.DynamiteModulesB:182)
                  at android.os.Binder.transact(Binder.java:380)
                  at com.google.android.gms.maps.internal.IGoogleMapDelegate$zza$zza.addGroundOverlay(Unknown Source)
                  at com.google.android.gms.maps.GoogleMap.addGroundOverlay(Unknown Source)
                  at br.com.imerljak.vegvisir.MapsActivity.onMapReady(MapsActivity.java:62)
                  at com.google.android.gms.maps.SupportMapFragment$zza$1.zza(Unknown Source)
                  at com.google.android.gms.maps.internal.zzt$zza.onTransact(Unknown Source)
                  at android.os.Binder.transact(Binder.java:380)
                  at xz.a(:com.google.android.gms.DynamiteModulesB:82)
                  at maps.ad.u$5.run(Unknown Source)
                  at android.os.Handler.handleCallback(Handler.java:739)
                  at android.os.Handler.dispatchMessage(Handler.java:95)
                  at android.os.Looper.loop(Looper.java:135)
                  at android.app.ActivityThread.main(ActivityThread.java:5312)
                  at java.lang.reflect.Method.invoke(Native Method)
                  at java.lang.reflect.Method.invoke(Method.java:372)
                  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:901)
                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:696)
PS:如果有人有任何技巧可以帮助我开发这个应用程序(就像一个很好的室内导航API),我将不胜感激:)

1 个答案:

答案 0 :(得分:0)

您的mapOverlay实例refence似乎无法正确初始化...