手机地图包returns地图为空

Mobile map package returns null for map

我下载了Arcgis示例mmpk文件,甚至我自己做了一个mmpk。
在这两个文件中,我都有 1 张地图(通过调试检查)但是当我尝试加载地图时(使用 Esri 指南页面中的代码)它 returns null 用于地图。
很高兴我可以在我的地图视图中显示在线地图,并且 android studio 没有显示任何警告或错误。

    import static n.k.masoud.sbmap.R.id.mapView;


    public class ActivityMain extends AppCompatActivity {
        private MapView mMapView;
        private ArcGISMap map;

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            mMapView = (MapView) findViewById(mapView);

code and file from main site

            try {File mmpkFile = new File(Environment.getExternalStorageDirectory(),"devlabs-package.mmpk");
            String mmpkPath = mmpkFile.getAbsolutePath();
            final MobileMapPackage mobileMapPackage=new MobileMapPackage(mmpkPath);


  mobileMapPackage.addDoneLoadingListener(new Runnable() {
       @Override
         public void run() {

this if gets false

             if (mobileMapPackage.getLoadStatus() == LoadStatus.LOADED) {
               showMessage(String.format("Number of maps = %d", mobileMapPackage.getMaps().size()));
map = mobileMapPackage.getMaps().get(0);
            } else {
               dealWithLoadFailure();
              }
           }
     });
       mobileMapPackage.loadAsync();
   }
    catch (Exception err){
      Log.e("TAG", "onCreate: "+err);
   }

          map.addDoneLoadingListener(new Runnable() {
              @Override
              public void run() {
                  if (map.getLoadStatus() == LoadStatus.LOADED) {
                     Log.e("TAG", "run: map loaded ok" );
                       // Once map is loaded, can check its properties and content
                    if (map.getBookmarks().size() > 0) {
}
                } else {
dealWithLoadFailure();
                 }
              }
            });
           map.loadAsync();

As I told part below works correctly

 //        for online maps
    //        ArcGISMap map = new ArcGISMap(Basemap.Type.TOPOGRAPHIC, 29.453826, 60.852134,12);

            mMapView.setMap(map);
mMapView.addLayerViewStateChangedListener(new LayerViewStateChangedListener() {
                @Override
                public void layerViewStateChanged(LayerViewStateChangedEvent layerViewStateChangedEvent) {
                    // Each layer may have more than one layer view state.
                    StringBuilder layerStatuses = new StringBuilder();
                    for (LayerViewStatus status : layerViewStateChangedEvent.getLayerViewStatus()) {
                        if (layerStatuses.length() > 0) {
                            layerStatuses.append(",");
                        } layerStatuses.append(status.name());
                    }
                    showMessage(String.format("Layer '%s' status=%s", layerViewStateChangedEvent.getLayer().getName(), layerStatuses.toString()));
                } });



        }
        @Override
        protected void onPause(){
            mMapView.pause();
            super.onPause();
        }

        @Override
        protected void onResume(){
            super.onResume();
            mMapView.resume();
        }

    }

如果行

if (mobileMapPackage.getLoadStatus() == LoadStatus.LOADED)

返回false,则移动地图包未加载且不包含任何地图。

在您的 dealWithLoadFailure() 函数中,您可以检索加载错误:

mobileMapPackage.getLoadError()

看看它是什么。它应该告诉您导致加载失败的错误是什么。

我的一个朋友试过这种方法,但和我一样没有得到任何结果。
所以他把官方的引导代码改成了这个,得到了很好的反响。 我认为他从互联网上获得了代码,所以我不知道它的版权许可。

 private void setupMobileMap() {
    if (mMapView != null) {
        File mmpkFile = new File(Environment.getExternalStorageDirectory(), "devlabs-package.mmpk");
        final MobileMapPackage mapPackage = new MobileMapPackage(mmpkFile.getAbsolutePath());
        mapPackage.addDoneLoadingListener(new Runnable() {
            @Override
            public void run() {
                // Verify the file loaded and there is at least one map
                if (mapPackage.getLoadStatus() == LoadStatus.LOADED && mapPackage.getMaps().size() > 0) {
                     mMapView.setMap(mapPackage.getMaps().get(0));
                } else {
                    // Error if the mobile map package fails to load or there are no maps included in the package
                    //setupMap();
                    //Log for Error
                }
            }
        });
        mapPackage.loadAsync();
    }
}