GPX를 KMl로 변환하지만 스타일 및 더 많은 DOM을 설정하는 방법은이 코드를 작성했습니다.
function gpxtokml($path,$id){
$name_file=$path;
$point=explode(".",$name_file);
$namekml=$point[0].'.kml';
$xml = simplexml_load_file($name_file);$i=0;
$arry=array();
foreach($xml->trk->trkseg->trkpt as $trkpt) {
//$arry[$i++]=$this->xml2array ($trkpt,$out = array());
foreach ((array) $trkpt as $index => $node){
//$out[$index] = (is_object ($node));
if(is_object ($node)){
foreach ((array) $trkpt as $index => $node)
$out[$index] = $node ;
continue;
}else{
$out[$index] = $node ;
}
}
$arry[$i++]=$out;
}
//print_r($arry);exit;
$retrn=$this->generatekml($arry,true,$namekml,$id);
return $retrn;
}
function xml2array ($xmlObject, $out = array())
{
foreach ((array) $xmlObject as $index => $node)
$out[$index] = (is_object ($node)) ? xml2array ($node) : $node;
return $out;
}
function generatekml($input,$file,$filename,$id){
$output="<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<kml xmlns=\"http://www.opengis.net/kml/2.2\">
<Document>
";
$i=1;
//echo '<pre>';print_r($input);exit;
foreach($input as $key=>$point){
$name="point ".$i++;
$description='';
$lat=$point['@attributes']['lat'];
$lon=$point['@attributes']['lon'];
$coordinates=$lat .",".$lon;
$output.="<Placemark>
<name>$name</name>
<description>$description</description>
<Point>
<coordinates>$coordinates</coordinates>
</Point>
</Placemark>
";
}
$output.="</Document>
</kml>
";
if($file){
//header("Content-type: octet/stream");
//header("Content-disposition: attachment; filename=".$filename.";");
// header("Content-lenght: ".filesize("files/".$file));
//echo $output;
$fl=time().'kml.kml';
$xmlfile=WWW_ROOT.'kmlfile/'.$fl;
//echo $this->EventDetail->id=$id;
//exit;
//$date['EventDetail']['kmlfile']=time().'kml.kml';
//$this->EventDetail->save($date['EventDetail'],false);
$fp = fopen($xmlfile, 'w');
fwrite($fp, $output);
fclose($fp);
//echo time().'kml.kml';
return $fl;
}else{
}
}
좋은 질문, +1. 설명과 세 가지 가능한 해결책에 대한 내 대답을 참조하십시오. –