Skip to content

Instantly share code, notes, and snippets.

@Firzen7
Last active March 2, 2020 14:21
Show Gist options
  • Save Firzen7/4bcbb55db9e85d69605e9ed2a6af41e3 to your computer and use it in GitHub Desktop.
Save Firzen7/4bcbb55db9e85d69605e9ed2a6af41e3 to your computer and use it in GitHub Desktop.
private GPSPoint gpsCentre(Collection<GPSPoint> points) {
float x = 0;
float y = 0;
float z = 0;
for(GPSPoint pt : points) {
final float lat = (float) pt.getLatitude();
final float lon = (float) pt.getLongitude();
x += Math.cos(lat) * Math.cos(lon);
y += Math.cos(lat) * Math.sin(lon);
z += Math.sin(lat);
}
x = (float) (x / points.size());
y = (float) (y / points.size());
z = (float) (z / points.size());
return new GPSPoint(Math.atan2(y, x), Math.atan2(z, Math.sqrt(x * x + y * y)));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment