我知道输入和输出是什么,但我不确定它是如何工作的或为什么工作。
此代码用于在给定包含一组点的最小和最大经度/纬度(正方形)的情况下,确定仍将显示所有这些点的 Google map 上的最大缩放级别。原作者已经不在了,所以我不确定这些数字中的一些是什么(即 6371 和 8)。把它当作一个谜题 =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(根据 IUGG)
DegToRadDivisor = 180/PI = 57.2958
再次,缩放级别每一步都会使大小加倍,即将缩放级别增加屏幕大小的一半。
zoom = 8 - log(factor * dist) / log(2) = 8 - log_2(factor * dist)
=> dist = 2^(8-zoom) / factor
从数字中我们发现缩放级别 8 对应于 276.89 公里的距离。
关于java - 这个谷歌地图缩放级别计算是如何工作的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5939983/