dig*_*tie 3 java android android-mapview
我有多个点放在我的MapView上,并希望将地图置于这些点上,即不是任何特定的点,只是它们的平均中心.
我知道在Javascript G. Maps API中有一种方法.我想知道在Android中是否有一种先行方法可以做到这一点?
Asa*_*saf 15
您要计算的内容称为Centroid.有几种Java实现用于计算有限点集(多边形)的质心.
例如:JavaGeom有执行查找的多的2D点的重心.
我不确定它是否有标准的Android实现,但是实现起来相当简单.
简单实施:
public static float[] centroid(float[] points) {
float[] centroid = { 0, 0 };
for (int i = 0; i < points.length; i+=2) {
centroid[0] += points[i];
centroid[1] += points[i+1];
}
int totalPoints = points.length/2;
centroid[0] = centroid[0] / totalPoints;
centroid[1] = centroid[1] / totalPoints;
return centroid;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
12476 次 |
| 最近记录: |