Android - 如何知道 mapView 是否正确加载? [英] Android - How to know if mapView is properly loaded?

查看:26
本文介绍了Android - 如何知道 mapView 是否正确加载?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在检测我的 android 地图应用程序中是否加载了 mapview 时遇到了问题.在 OnCreate 方法中,当我分配地图 URL 时,我想知道是否发生了任何问题.由于我的互联网连接或任何其他问题(例如从 REST 服务加载地图),可能会出现问题.这是我的代码块;

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 may occur due to my internet connection or any other problems like loading the map from REST services. Here is my code block;

map.addLayer(newArcGISDynamicMapServiceLayer("any map URL"));

此后,我尝试使用 if(map.isLoaded==false) 之类的控件,但它不起作用,尽管地图已正确加载,但它属于此块.

after this point, I try to use a control like if(map.isLoaded==false) but it does not work, although map is loaded properly it falls into this block.

有人可以帮我吗?

提前致谢

推荐答案

听起来可能发生的事情是代码在初始化之前检查 map.isLoaded().查看 MapView Reference 以获取有关如何操作的官方说明正确检查初始化.

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.

我已经扩展了参考代码

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

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


    map.setOnStatusChangedListener(new OnStatusChangedListener() {
       private static final long serialVersionUID = 1L;

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

这篇关于Android - 如何知道 mapView 是否正确加载?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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