Skip to content

Instantly share code, notes, and snippets.

@juice49
Created April 13, 2012 14:00
Show Gist options
  • Save juice49/2377074 to your computer and use it in GitHub Desktop.
Save juice49/2377074 to your computer and use it in GitHub Desktop.
<?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;
?>
<?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