Ale*_*ley 11 java algorithm google-maps latitude-longitude
我知道输入和输出是什么,但我不确定它是如何工作的或原因.
此代码用于给定包含一组点的最小和最大经度/纬度(正方形),确定Google地图上仍将显示所有这些点的最大缩放级别.原作者已经不见了,所以我不确定这些数字中的一些是什么(即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;
}
Run Code Online (Sandbox Code Playgroud)
Ken*_*Ken 12
我使用下面的简单公式:
public int getZoomLevel(Circle circle) {
if (circle != null){
double radius = circle.getRadius();
double scale = radius / 500;
zoomLevel =(int) (16 - Math.log(scale) / Math.log(2));
}
return zoomLevel;
}
Run Code Online (Sandbox Code Playgroud)
您也可以用其特定半径替换圆.
How*_*ard 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
Run Code Online (Sandbox Code Playgroud)
从数字我们发现,缩放级别8对应的距离为276.89km.