mirror of
https://github.com/wavelog/wavelog.git
synced 2026-03-22 10:24:14 +00:00
Static Map API (#1098)
Added new Static Map Feature --------- Co-authored-by: phl0 <github@florian-wolters.de>
This commit is contained in:
@@ -166,6 +166,39 @@ class Qra {
|
||||
//return findings
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to calculate the center of a bunch of coordinates
|
||||
* Source: https://www.phpsnippet.com/snippet/center-point-of-multiple-gps-coordinates-with-php
|
||||
*
|
||||
* @param array $coordinates Array of coordinates [latitude, longitude]
|
||||
* Example:
|
||||
* $coordinates = [
|
||||
* [37.7797, -122.41924],
|
||||
* [37.77323, -122.41114],
|
||||
* [37.79203, -122.40864],
|
||||
* [37.7952, -122.4222]
|
||||
* ];
|
||||
*
|
||||
* @return array [latitude, longitude] Center of the coordinates
|
||||
*/
|
||||
|
||||
function getCenterLatLng($coordinates) {
|
||||
$x = $y = $z = 0;
|
||||
$n = count($coordinates);
|
||||
foreach ($coordinates as $point)
|
||||
{
|
||||
$lt = $point[0] * pi() / 180;
|
||||
$lg = $point[1] * pi() / 180;
|
||||
$x += cos($lt) * cos($lg);
|
||||
$y += cos($lt) * sin($lg);
|
||||
$z += sin($lt);
|
||||
}
|
||||
$x /= $n;
|
||||
$y /= $n;
|
||||
|
||||
return [atan2(($z / $n), sqrt($x * $x + $y * $y)) * 180 / pi(), atan2($y, $x) * 180 / pi()];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user