1. Go to this page and download the library: Download plin-code/kml-parser library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
plin-code / kml-parser example snippets
return [
/*
|--------------------------------------------------------------------------
| Default KML Namespace
|--------------------------------------------------------------------------
|
| This value is the default namespace used for parsing KML files.
| Usually you don't need to change this.
|
*/
'namespace' => 'http://www.opengis.net/kml/2.2',
/*
|--------------------------------------------------------------------------
| Temporary Directory
|--------------------------------------------------------------------------
|
| This value determines the temporary directory used for extracting KMZ files.
| If null, the system temp directory will be used.
|
*/
'temp_directory' => null,
];
use PlinCode\KmlParser\KmlParser;
// Parse a KML file
$parser = new KmlParser();
$parser->loadFromFile('path/to/file.kml');
// Get placemarks (points of interest)
$placemarks = $parser->getPlacemarks();
// Get styles
$styles = $parser->getStyles();
// Get style maps
$styleMaps = $parser->getStyleMaps();
// Get document name and description
$name = $parser->getDocumentName();
$description = $parser->getDocumentDescription();
// Convert to GeoJSON
$geoJson = $parser->toGeoJson();
// Parse a KMZ file
$parser = new KmlParser();
$parser->loadFromKmz('path/to/file.kmz');
// Work with the data just like with KML
$placemarks = $parser->getPlacemarks();
use PlinCode\KmlParser\KmzExtractor;
$extractor = new KmzExtractor();
$files = $extractor->extractAllFiles('path/to/file.kmz', 'extraction/directory');
use PlinCode\KmlParser\Facades\KmlParser;
$placemarks = KmlParser::loadFromFile('path/to/file.kml')->getPlacemarks();