Created
April 13, 2012 14:00
-
-
Save juice49/2377074 to your computer and use it in GitHub Desktop.
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 characters
<?php | |
ini_set('display_errors',1); | |
error_reporting(E_ALL); | |
require 'kml-parser.php'; | |
$kml = file_get_contents('http://maps.google.co.uk/maps/ms?ie=UTF8&hl=en&t=h&authuser=0&msa=0&output=kml&msid=210156054229171524633.0004a10ec7664b0c32ce8'); | |
$kmlParser = new KmlParser($kml); | |
echo $kmlParser->output; | |
?> |
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 characters
<?php | |
class KmlParser { | |
private $kml; | |
public $output; | |
public function __construct($XML) { | |
$this->kml = new DOMDocument; | |
$this->kml->loadXML($XML); | |
$this->output = json_encode($this->parse()); | |
} | |
private function parse() { | |
$coordinates = $this->kml->getElementsByTagName('coordinates'); | |
$output = array(); | |
foreach($coordinates as $coordinate) { | |
$latLng = $coordinate->nodeValue; | |
$latLngComponents = explode(',', $latLng); | |
$marker = array( | |
'name' => '', | |
'position' => array( | |
'lat' => $latLngComponents[1], | |
'long' => $latLngComponents[0] | |
), | |
'icon' => './img/blue-dot.png' | |
); | |
array_push($output, $marker); | |
} | |
return $output; | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment