Le blog de Vincent Battaglia

Générez vos fichiers KML automatiquement avec l’aide de PHP

17/05

Ça pourrait vous être utile. Il s’agit d’un fichier PHP auquel vous passez les coordonnées GPS d’un point et qui vous crée automatiquement un fichier KML pour Google Earth.

<?php
header("Content-Type: application/vnd.google-earth.kml+xml");
header("Content-Disposition: attachment; filename=location.kml");
$x = $_GET['x'];
$y = $_GET['y'];
echo('<?xml version="1.0" encoding="utf-8"?>');
?>

<kml xmlns="http://earth.google.com/kml/2.1">
  <Document>
		<Placemark>
			<Point>
				<coordinates><?php echo $x; ?>,<?php echo $y; ?></coordinates>
			</Point>
		</Placemark>
	</Document>
</kml>

Note : j’ai placé la déclaration XML dans un echo car ça entrait en conflit avec les déclarations PHP.

Un exemple ici (ma maison) : http://www.vinch.be/attic/kml.php?x=4.186022&y=50.636758

5 commentaires

Laisser un commentaire

1MD