首页 > 学院 > 开发设计 > 正文

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

2019-11-09 14:44:31
字体:
来源:转载
供稿:网友

方法一:

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


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表