简体   繁体   中英

Reading kml file

i download a KML file..Is there any way to use javascript/php to loop through the file and get all the coordinates in the KML file?

Thanks

You can use jquery ajax to read/loop the file. Just like normal XML.

More info for using jquery. http://api.jquery.com/jQuery.ajax/

If the KML file is of a decent size, then it could be very worthwhile to first convert it to JSON (in PHP) before sending it to the user's browser. JSON will produce a lower filesize and also be faster to parse (which could be of marginal benefit if the KML file is small, but very noticeable if it's complex).

// PHP:
$json = json_encode(simplexml_load_string($xml_string));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM