-2
我有一個PHP函數可以創建一個kml文件。 (我驗證了輸出,它是一個有效的KML文件)。谷歌地圖不鏈接kml文件
然後,我用谷歌地圖與這些文件,但我不知道爲什麼,在地圖上顯示無數據...
在PHP中,我有這樣的:
//some stuff here
return 'iniMap("", "", "http://my.web.com/Class/API/GMaps/Rep/'.$g->make($l, $a, $user).'.kml")';
這函數通過AJAX調用,所以返回的字符串將使用JS「eval()」進行評估。我的谷歌地圖功能:
/*GOOGLE MAPS FUNCTIONS*/
function iniMap(x,y,url){
n=document.createElement('DIV');
n.id='map_canvas';
ge('con').appendChild(n);
var latlng=new google.maps.LatLng(x,y);
var map=new google.maps.Map(ge("map_canvas"),{zoom:6,center:latlng,mapTypeId:google.maps.MapTypeId.ROADMAP});
var div1=document.createElement('DIV');
var homeControl1=new makeControl(div1,'t1');
var div2=document.createElement('DIV');
var homeControl2=new makeControl(div2,'t2');
var div3=document.createElement('DIV');
var homeControl3=new makeControl(div3,'t3');
var div4=document.createElement('DIV');
var homeControl4=new makeControl(div4,'t4');
var ctaLayer=new google.maps.KmlLayer(url);
div1.index = 1;
map.controls[google.maps.ControlPosition.TOP_RIGHT].push(div1);
div2.index = 2;
map.controls[google.maps.ControlPosition.TOP_RIGHT].push(div2);
div3.index = 3;
map.controls[google.maps.ControlPosition.TOP_RIGHT].push(div3);
div4.index = 4;
map.controls[google.maps.ControlPosition.TOP_RIGHT].push(div4);
ctaLayer.setMap(map);
}
function makeControl(d,t){
d.style.padding='5px';
var controlUI=document.createElement('DIV');
controlUI.style.backgroundColor='#FEFEFE';
controlUI.style.borderStyle='solid';
controlUI.style.borderWidth='1px';
controlUI.style.cursor='pointer';
controlUI.style.textAlign='center';
controlUI.style.width='60px';
controlUI.style.height='17px';
d.appendChild(controlUI);
var controlText=document.createElement('DIV');
controlText.style.fontFamily='Arial,sans-serif';
controlText.style.fontSize='12px';
controlText.style.paddingLeft='4px';
controlText.style.paddingRight='4px';
controlText.innerHTML=t;
controlUI.appendChild(controlText);
google.maps.event.addDomListener(controlUI,'click',function(){doAction(t);});
}
function doAction(t){
if(t=='t1'){document.location.href='http://my.web.com?t=sy0'}
else if(t=='t2'){document.location.href='http://my.web.com?t=sm0'}
else if(t=='t3'){document.location.href='http://my.web.com?t=sw0'}
else if(t=='t4'){document.location.href='http://my.web.comt=sd0'}
}
我做錯了嗎? 謝謝!
是您的KML文件[託管在一個公開的Web服務器(https://developers.google.com/maps/documentation/javascript/reference #KmlLayer)? – geocodezip 2013-05-07 12:36:02
是的。我的意思是,我可以把「my.web.com/Class/API/GMaps/Rep/name_of_file.kml」和谷歌Chrome下載它... – David 2013-05-07 13:11:28
my.web.com看起來並不像一個公開的網絡服務器。問題是谷歌可以將它下載到他們的服務器來渲染圖塊,而不是在瀏覽器中下載它。如果您將網址傳遞到[Google地圖](http://maps.google.com),會發生什麼情況,例如[this](https://maps.google.com/maps?q=http:%2F%2Fwww。 geocodezip.com%2Fgeoxml3_test%2Fso_kml.kml&HL = EN&SLL = 32.824552,-117.108978&SSPN = 0.691256,0.883026&T = H&Z = 16)? – geocodezip 2013-05-07 13:38:11