Created
May 6, 2014 16:16
-
-
Save korkey128k/16fdfb2f5f04d91e392f to your computer and use it in GitHub Desktop.
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 | |
$xml = new DOMDocument(); | |
$xml->validateOnParse = true; | |
$file_path = ''; // FilePath. Dur | |
if(@$xml->loadXML(file_get_contents($file_path))) : | |
$coordinates = $xml->getElementsByTagName('coordinates'); | |
foreach ($coordinates as $coordinate) { | |
$coord_list[] = $coordinate->nodeValue; | |
} | |
// Clean up the coordinates | |
foreach ($coord_list as $coordinates) { | |
$coordinates = explode(',0 ', $coordinates); | |
$coordinates = array_filter($coordinates); | |
$coordinates = array_map('trim', $coordinates); | |
} | |
$longs = array(); | |
$lats = array(); | |
foreach($coordinates as $index => $coordinate_set) { | |
$coords = explode(',', $coordinate_set); | |
(!empty($coords[0])) ? array_push($longs, $coords[0]) : ''; | |
(!empty($coords[1])) ? array_push($lats, $coords[1]) : ''; | |
} | |
$longitude = array_sum($longs) / count($longs); | |
$latitude = array_sum($lats) / count($lats); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment