Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function GetCenterFromDegrees(array $data)
- {
- if (!count($data)) {
- return false;
- }
- $numCoords = count($data);
- $X = 0.0;
- $Y = 0.0;
- $Z = 0.0;
- for($i = 0; $i < count($data); $i++){
- $lat = $data[$i][0] * pi() / 180;
- $lon = $data[$i][1] * pi() / 180;
- $a = cos($lat) * cos($lon);
- $b = cos($lat) * sin($lon);
- $c = sin($lat);
- $X += $a;
- $Y += $b;
- $Z += $c;
- }
- $X /= $numCoords;
- $Y /= $numCoords;
- $Z /= $numCoords;
- $lon = atan2($Y, $X);
- $hyp = sqrt($X * $X + $Y * $Y);
- $lat = atan2($Z, $hyp);
- $newX = ($lat * 180 / pi());
- $newY = ($lon * 180 / pi());
- return [$newX, $newY];
- }
Add Comment
Please, Sign In to add comment