【发布时间】:2011-08-21 20:25:21
【问题描述】:
我知道输入和输出是什么,但我只是不确定它是如何工作或为什么工作的。
此代码用于在给定包含一组点的最小和最大经度/纬度(正方形)的情况下确定 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;
}
【问题讨论】:
-
如果你看到原作者,用鳟鱼打他一巴掌;) 如此广泛地使用幻数 (en.wikipedia.org/wiki/Magic_number_%28programming%29) 被认为是糟糕的编码风格。
-
这是解释的方程式,Distance Calc 6371 是地球的半径,以公里为单位。
标签: java algorithm google-maps latitude-longitude