这个谷歌地图缩放级别计算是如何工作的? [英] How does this Google Maps zoom level calculation work?

查看:62
本文介绍了这个谷歌地图缩放级别计算是如何工作的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道输入和输出是什么,但我不确定它是如何或为什么起作用.

I know what the input and outputs are, but I'm just not sure how or why it works.

此代码用于在给定包含一组点的最小和最大经度/纬度(一个正方形)的情况下,确定仍将显示所有这些点的 Google 地图上的最大缩放级别.原作者已经走了,所以我不确定其中一些数字是什么(即 6371 和 8).把它当作一个谜 =D

This code is being used to, given a min and max longitude/latitude (a square) that contains a set of points, determine the maximum zoom level on Google Maps that will still display all of those points. The original author is gone, so I'm not sure what some of these numbers are even for (i.e. 6371 and 8). Consider it a puzzle =D

int mapdisplay = 322; //min of height and width of element which contains the map
double dist = (6371 * Math.acos(Math.sin(min_lat / 57.2958) * Math.sin(max_lat / 57.2958) + 
            (Math.cos(min_lat / 57.2958) * Math.cos(max_lat / 57.2958) * Math.cos((max_lon / 57.2958) - (min_lon / 57.2958)))));

double zoom = Math.floor(8 - Math.log(1.6446 * dist / Math.sqrt(2 * (mapdisplay * mapdisplay))) / Math.log (2));

if(numPoints == 1 || ((min_lat == max_lat)&&(min_lon == max_lon))){
    zoom = 11;
}

推荐答案

有些数字很容易解释

  • MeanRadiusEarthInKm = 6371 (according to IUGG)

DegToRadDivisor = 180/PI = 57.2958

DegToRadDivisor = 180/PI = 57.2958

再次,缩放级别每一步都将尺寸加倍,即将缩放级别增加屏幕尺寸的一半.

And again the zoom level doubles the size with each step, i.e. increase the zoomlevel by one halfs the size on the screen.

zoom = 8 - log(factor * dist) / log(2) = 8 - log_2(factor * dist)
=> dist = 2^(8-zoom) / factor

从数字中我们发现缩放级别 8 对应的距离为 276.89 公里.

From the numbers we find that zoom level eight corresponds to a distance of 276.89km.

这篇关于这个谷歌地图缩放级别计算是如何工作的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆