Created
May 6, 2014 16:16
-
-
Save korkey128k/16fdfb2f5f04d91e392f to your computer and use it in GitHub Desktop.
Revisions
-
korkey128k created this gist
May 6, 2014 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,34 @@ <?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); ?>