Skip to content

Instantly share code, notes, and snippets.

@korkey128k
Created May 6, 2014 16:16
Show Gist options
  • Save korkey128k/16fdfb2f5f04d91e392f to your computer and use it in GitHub Desktop.
Save korkey128k/16fdfb2f5f04d91e392f to your computer and use it in GitHub Desktop.
<?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