Android - 如何知道mapView是否正确加载?

发布于 2024-12-28 13:32:52 字数 328 浏览 3 评论 0原文

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

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

之后,我尝试使用像 if(map.isLoaded==false) 这样的控件,但它不起作用,尽管地图已正确加载,但它落入此块。

谁能帮助我吗?

提前致谢

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"));

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.

Can anyone help me?

Thanks in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

迷鸟归林 2025-01-04 13:32:52

听起来可能发生的情况是代码在初始化之前检查 map.isLoaded() 。请查看 MapView 参考,了解有关如何操作的官方说明正确检查初始化。

我已经扩展了参考代码

    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();
            }
        }
     });

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 = 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();
            }
        }
     });
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文