如何获得一些位置之间的中心点(LatLng)? [英] How to get center point(LatLng) between some locations?

查看:539
本文介绍了如何获得一些位置之间的中心点(LatLng)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以帮助我获得中心点。我有6 LatLng对象,现在我需要得到一个LatLng对象是中心。非常感谢!

解决方案

您需要计算您的点定义的多边形的质心。 Wikipedia 将质心定义为:


平面图形的质心或几何中心是形状中所有点的算术平均值(平均)位置

要计算有限点集的质心,您可以使用以下方法:

  private LatLng computeCentroid(List< LatLng> points){
double latitude = 0;
double longitude = 0;
int n = points.size();

(LatLng point:points){
latitude + = point.latitude;
longitude + = point.longitude;
}

返回新的LatLng(纬度/ n,经度/ n);
}


Anyone can help me get center point. I have 6 LatLng objects, now i need to get a LatLng object is center. Many thanks!

解决方案

You need to calculate the centroid of the polygon defined by your points. Wikipedia defines the centroid as:

The centroid or geometric center of a plane figure is the arithmetic mean ("average") position of all the points in the shape

To calculate the centroid of a finite set of points you can use the following method:

private LatLng computeCentroid(List<LatLng> points) {
    double latitude = 0;
    double longitude = 0;
    int n = points.size();

    for (LatLng point : points) {
        latitude += point.latitude;
        longitude += point.longitude;
    }

    return new LatLng(latitude/n, longitude/n);
}

这篇关于如何获得一些位置之间的中心点(LatLng)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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