Created
May 20, 2011 12:59
-
-
Save ClementGautier/982842 to your computer and use it in GitHub Desktop.
Trying to build a function that find the center of a Polygon defined by geo coordinates
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$coords = array( | |
array('lat' => 2.125397, 'long' => 48.98255900000001), | |
array('lat' => 2.205048, 'long' => 48.620747), | |
array('lat' => 2.759857, 'long' => 48.769405), | |
array('lat' => 2.457733, 'long' => 49.171471), | |
); | |
// premier test | |
$bar = array( | |
'lat' => array('degre' => 0, 'decim' => 0), | |
'long' => array('degre' => 0, 'decim' => 0) | |
); | |
foreach($coords as $coord) { | |
$bar['lat']['degre'] += abs($coord['lat']); | |
$bar['lat']['decim'] += ($coord['lat'] - (int) $coord['lat']); | |
$bar['long']['degre'] += abs($coord['long']); | |
$bar['long']['decim'] += ($coord['long'] - (int) $coord['long']); | |
} | |
// @ToDo: récupérer la partie décimale de la division de la partie entière. | |
$barFinal = array( | |
'lat' => (float)((int)($bar['lat']['degre'] / sizeof($coords)) + ($bar['lat']['decim'] / sizeof($coords))), | |
'long' => (float)((int)($bar['long']['degre'] / sizeof($coords)) + ($bar['long']['decim'] / sizeof($coords))), | |
); | |
echo "initial coords :<br />"; | |
var_dump($coords); | |
echo "<br />bar coords :<br />"; | |
var_dump($barFinal); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment