根据圆心经纬度和半径计算地图zoom level

本文介绍了两种基于地理位置和精度范围来确定地图合理缩放级别的计算方法。方法一通过计算经度差值来推导出适合的地图显示比例,而方法二则通过所需的像素间距来计算出合适的缩放级别。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

方法一:

private double calZoomLevel(LatLng latLng, float radius) {

        double equatorLength = 40075004.0;
        double earthRadius = 6371229;

        double numerator = 1 + Math.pow((float)mMapView.getHeight()/(float)mMapView.getWidth(), 2);
        double denominator =  Math.pow(radius, 2);
        double distance = Math.sqrt(denominator/numerator);

        double longitudeDelta = (180 * distance)/(Math.PI * earthRadius * Math.cos(latLng.latitude * Math.PI/180));

        int width = DisplayUtil.dpFromPx(this, mMapView.getWidth());

        double tt = longitudeDelta * equatorLength * Math.PI / (180.0 * width);
        double zoom = 21 - Math.log(tt)/Math.log(2.0);
        return zoom;
    }

方法二:

private double calZoomLevel2(LatLng latLng, float radius) {

        // Equators length
        double equatorLength = 40075004.0;

        double distance = radius * 2;

        DisplayMetrics metrics = new DisplayMetrics();
        getWindowManager().getDefaultDisplay().getMetrics(metrics);
        // Use min(width, height) (to properly fit the screen
        int screenSize = Math.min(metrics.widthPixels, metrics.heightPixels);

        // The meters per pixel required to show the whole area the user might be located in
        double requiredMpp = distance/screenSize;

        // Calculate the zoom level
        double zoomLevel = ((Math.log(equatorLength / (256 * requiredMpp))) / Math.log(2)) + 1;
        return zoomLevel;
    }

附上参考链接:

http://stackoverflow.com/questions/18383236/determine-a-reasonable-zoom-level-for-google-maps-given-location-accuracy

http://blog.sina.com.cn/s/blog_49cc672f0100elsb.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值