Skip to content Skip to sidebar Skip to footer

Android - How To Know If Mapview Is Properly Loaded?

I am having trouble in detecting if mapview is loaded in my android map appication. In OnCreate method, when I assign the map URL, I want to know if any problem occured. Problems m

Solution 1:

Sounds like what might be happening is the code is checking map.isLoaded() before it has been initialized. Check MapView Reference for the official explanation on how to properly check for initialization.

I've expanded on the reference code

    map = (MapView) findViewById(R.id.map);
    tileLayer = newArcGISTiledMapServiceLayer("http://services.arcgisonline.com/ArcGIS/rest/services/World_Shaded_Relief/MapServer");

    tileLayer.setOnStatusChangedListener(newOnStatusChangedListener() {
        publicvoidonStatusChanged(Object source, STATUS status) {
            if (OnStatusChangedListener.STATUS.INITIALIZED == status){
                map.addLayer(tileLayer);  //when layer is initialized add to map
            }
        }
    });


    map.setOnStatusChangedListener(newOnStatusChangedListener() {
       privatestaticfinallongserialVersionUID=1L;

       publicvoidonStatusChanged(Object source, STATUS status) {
           //conditional checks if mapView's status has changed to initialized if (OnStatusChangedListener.STATUS.INITIALIZED == status && source == map) 
            { 
                ToastmapViewToast= Toast.makeText(ActivityName.this, "MapView loaded", Toast.LENGTH_LONG);
                mapViewToast.show();
            }
        }
     });

Post a Comment for "Android - How To Know If Mapview Is Properly Loaded?"