2012-09-17 41 views
0

我通過谷歌地球api打開kmz文件時遇到問題。在asp.net中跨域打開kmz文件mvc

google.earth.fetchKml(ge, 'http://10.122.150.183:8008/test.kmz', checkForCoordinates); 

但是,當我更改鏈接到另一個域文件(這是WCF服務):'https://10.122.150.183:4431/Uploads/1/test.kmz',文件確實在谷歌地球不開的時候我提供服務器的靜態鏈接到文件它工作正常。我試過另一種解決方案:從ASP.Net MVC控制器動態提供KMZ文件,返回:

return File(fileStream, "application/vnd.google-earth.kmz kmz", fileName); 

,如果我嘗試從瀏覽器的地址欄中得到它它工作正常,但是當我提供鏈接到行動在fetchKml方法中,動作甚至不吸氣。

關於如何從另一個域打開kmz文件的任何建議?

回答

0

我已經在wcf中實現了Kmz文件生成器。該服務返回Stream類型對象,其傳出響應內容類型設置爲「application/vnd.google-earth.kmz」。

的代碼看起來象

public class Kmz 
{ 
    public static Stream Generate(string stringKml, string fileName) 
    { 
     MemoryStream stream = new MemoryStream(); 
     using (ZipFile zip = new ZipFile()) 
     { 
      zip.AddEntry(fileName, stringKml); 
      zip.Save(stream); 
     } 

     WebOperationContext.Current.OutgoingResponse.ContentType = "application/vnd.google-earth.kmz"; 

     stream.Position = 0; 
     return stream; 
    } 
} 

希望它幫助。

0

您也可以使用javascript的iframe或腳本方式加載kml內容,這兩種方式可以讓您從不同的域加載資源,然後使用parseKml函數來解析kml內容並將其添加到您的地球中。

希望它有幫助。