Google지도를 사용하여 PHP 스크립트를 호출하여 XML 형식으로 KML 레이어를 출력하여 데이터베이스에서 다양한 데이터 레이어를 가져오고 전환 할 수있는지도를 만듭니다. 아래 코드를 실행하면 아무 일도 일어나지 않으며 콘솔 오류도 발생하지 않습니다. 내 테스트에서 정확히 작동하는 XML 데이터 레이어와 동일하므로 반환 된 XML이 확실하다는 것을 알고 있습니다. Google지도 오버레이 오류
header("Content-type: text/xml");
echo '<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://earth.google.com/kml/2.1">
<Document>
<Style id="a">
<IconStyle>
<Icon>
<href>http://maps.google.com/mapfiles/ms/icons/yellow-dot.png</href>
</Icon>
</IconStyle>
</Style>';
// Iterate through the rows, printing XML nodes for each
while ($row = @mysql_fetch_assoc($result)){
// ADD TO XML DOCUMENT NODE
echo '<Placemark><name>' . parseToXML($row['name']) . '</name><styleUrl>#a</styleUrl><point><coordinates>' . $row['lat'] . ',' . $row['lng'] . '</coordinates></point><description>' . parseToXML($row['name']) . '</description></Placemark>';
}
// End XML file
echo '</Document>
</kml>';
내가 반드시 사람을 찾는 게 아니에요 SQL_map.php
의HTML
function downloadUrl(url,callback) {
var request = window.ActiveXObject ?
new ActiveXObject('Microsoft.XMLHTTP') :
new XMLHttpRequest;
request.onreadystatechange = function() {
if (request.readyState == 4) {
callback(request, request.status);
}
};
request.open('GET', url, true);
request.send(null);
}
$(document).ready(function() {
$('.kml_item').toggle(
function() {
$(this).animate({backgroundColor: '#ffffff'}, 200);
downloadUrl("SQL_map.php", function(data) {
var xml = data.responseXML;
var kmlxml = new google.maps.KmlLayer(xml);
kmlxml.setMap(the_Map);
});
관련 부분은 나에게 내가 할 노력하고있어에 대한 전체 코드를 제공하지만,에 진짜 질문은 데이터를 가져 와서지도에 배치하는이 방법이 실제로 가능한지 여부입니다. 나는 몇 가지 다른 방법을 시도했다. 각각 다른 방법으로 문제를 해결했다.
http://stackoverflow.com/questions/3514785/loading-a-local-kml-file-using-google-maps –