2

我正在尝试获取我的地图视图的范围,但我遇到的问题是纬度始终设置为 0,而经度始终设置为 360*1E6。根据这个链接,那是因为它只会在地图完全加载时提供正确的坐标: Mapview getLatitudeSpan and getLongitudeSpan not working

现在,我对解决方案完全感到困惑,我做了这个方法,我从我的 mainactivity (地图视图)的 onCreate 调用:

public int[][] getBounds()
{
 GeoPoint center = this.mapView.getMapCenter();
 int latitudeSpan = this.mapView.getLatitudeSpan();
 int longtitudeSpan = this.mapView.getLongitudeSpan();
 int[][] bounds = new int[2][2];

 bounds[0][0] = center.getLatitudeE6() + (latitudeSpan/2);
 bounds[0][1] = center.getLongitudeE6() + (longtitudeSpan/2);

 bounds[1][0] = center.getLatitudeE6() - (latitudeSpan/2);
 bounds[1][1] = center.getLongitudeE6() - (longtitudeSpan/2);
 return bounds;
}

如何让这个等待地图视图加载?我已经查看了 postDelayed 的 API,但我无法让它工作。

如果我是愚蠢的,请原谅我

4

1 回答 1

3

在 android 中创建“计时器”的正确方法是利用android.os.Handler

private Handler updateHandler = new Handler(); 

updateHandler.postDelayed(waitForMapTimeTask, TIME_TO_WAIT_IN_MS);

private Runnable waitForMapTimeTask = new Runnable() {
    public void run() {
        getBounds();
        // Read the bounds to see if something reasonable is returned
        if (!mapIsLoaded) {
            updateHandler.postDelayed(waitForMapTimeTask, TIME_TO_WAIT_IN_MS);
        }
    }
};
于 2010-11-22T14:41:19.333 回答