Kml.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. declare(strict_types=1);
  3. /*
  4. * This file is part of the Geocoder package.
  5. * For the full copyright and license information, please view the LICENSE
  6. * file that was distributed with this source code.
  7. *
  8. * @license MIT License
  9. */
  10. namespace Geocoder\Dumper;
  11. use Geocoder\Location;
  12. /**
  13. * @author Jan Sorgalla <jsorgalla@googlemail.com>
  14. */
  15. final class Kml extends AbstractDumper implements Dumper
  16. {
  17. /**
  18. * {@inheritdoc}
  19. */
  20. public function dump(Location $location): string
  21. {
  22. $name = $this->formatName($location);
  23. $kml = <<<'KML'
  24. <?xml version="1.0" encoding="UTF-8"?>
  25. <kml xmlns="http://www.opengis.net/kml/2.2">
  26. <Document>
  27. <Placemark>
  28. <name><![CDATA[%s]]></name>
  29. <description><![CDATA[%s]]></description>
  30. <Point>
  31. <coordinates>%.7F,%.7F,0</coordinates>
  32. </Point>
  33. </Placemark>
  34. </Document>
  35. </kml>
  36. KML;
  37. $lat = null;
  38. $lon = null;
  39. if (null !== $coordinates = $location->getCoordinates()) {
  40. $lat = $coordinates->getLatitude();
  41. $lon = $coordinates->getLongitude();
  42. }
  43. return sprintf($kml, $name, $name, $lon, $lat);
  44. }
  45. }