在android map v2中从半径计算缩放级别

时间:2014-07-09 08:51:09

标签: zoom android-mapview

我通过以下公式计算出的半径:

    public double getRadius() {
        double latitudeSpan = 0;
        VisibleRegion vr = mapView.getProjection().getVisibleRegion(); 
        float [] results = new float[3];
        Location.distanceBetween(vr.farLeft.latitude, vr.farLeft.longitude, vr.farRight.latitude, vr.farRight.longitude, results);
        latitudeSpan = results[0];
        return latitudeSpan;        
}

但现在我想稍后使用此半径设置相同的缩放级别。 我使用以下公式计算了缩放级别:

public static float zoom(double distance, Activity ctx) {
        byte zoom = 1;
        WindowManager windowManager = (WindowManager) ctx.getApplicationContext().getSystemService(Context.WINDOW_SERVICE);
        int widthInPixels = windowManager.getDefaultDisplay().getWidth();
        double equatorLength = 6378136.28;//in meters
        double metersPerPixel = equatorLength / 256;
        while ((metersPerPixel * widthInPixels) > distance) {
            metersPerPixel /= 2;
            ++zoom;
        }
        if (zoom > 21)
        zoom = 21;
        if (zoom < 1)
        zoom = 1;
        return zoom;
    }

但是我没有找到整数的缩放级别,而是如何找到之前的精确缩放级别(浮动)。请问有人帮我吗?

0 个答案:

没有答案