如何做到这一点谷歌地图缩放比例计算的工作? [英] How does this Google Maps zoom level calculation work?

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

问题描述

我知道的输入和输出,但我只是不知道如何和为什么它的工作原理。

这code被用于给定一个最小和最大经度/纬度(正方形),其中包含的点的集合,决定对谷歌地图的最大缩放级别,将仍显示所有的点。原作者已经一去不复返了,所以我不知道有些数字甚至对(即6371和8)。认为这是一个难题= D

  INT mapdisplay = 322; //高度和宽度的元件的分,其中包含在地图
双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)))));

双变焦= Math.floor(8  - 将Math.log(1.6446 * DIST /的Math.sqrt(2 *(mapdisplay * mapdisplay)))/将Math.log(2));

如果(为NumPoints == 1 ||((min_lat == max_lat)及及(min_lat == max_lat))){
    变焦= 11;
}
 

解决方案

一些数字可以很容易地解释

和再缩放级别的两倍长,每个步骤,即增加缩放级别被一个半区的大小的屏幕上。

 变焦= 8  - 日志(系数* DIST)/日志(2)= 8  -  log_2(系数* DIST)
=> DIST = 2 ^(8变焦)/因子
 

从数字,我们发现,变焦八级相当于276.89公里的距离。

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

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_lat == max_lat))){
    zoom = 11;
}

解决方案

Some numbers can be explained easily

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

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

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

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