簡體   English   中英

Google Maps Javascript API v3中的KML層問題

[英]KML layer problems in Google Maps Javascript API v3

這是我的代碼:

<html><head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<style type="text/css">
  html { height: 100% }
  body { height: 100%; margin: 0; padding: 0 }
  #map-canvas { height: 500px; width: 500px; }
</style>
<title>Map Your Reps</title>
<script type="text/javascript" src="https://maps.googleapis.com/maps/api  /js?key={key}"></script>
<script type="text/javascript">
  function initialize() {
    var mapOptions = {
      center: new google.maps.LatLng(-34, 92),
      zoom: 7
    };
    var map = new google.maps.Map(document.getElementById("map-canvas"), mapOptions);

    var kmlUrl = "http://{HOST}/kml/file.kml";
    var kmlOptions = {
        suppressInfoWindows: true,
        preserveViewport: false,
        map: map
    };
    var kmlLayer = new google.maps.KmlLayer(kmlUrl, kmlOptions);
  }
  google.maps.event.addDomListener(window, 'load', initialize);
</script>
</head>

<body>
<h1>Map</h1>
<div id="map-canvas"/>
</body></html>

由於某些原因,.kml文件雖然可以公共訪問,但並未被API加載。

我在Chrome開發者工具的網絡標簽中注意到以下要求:

https://maps.googleapis.com/maps/api/js/KmlOverlayService.GetOverlays?1shttp%3A%2F%2F{HOST}%2Fkml%2Ffile.kml&callback=_xdc_._9dx071&token=97074

響應為:/ /**/_xdc_._9dx071 && _xdc_._9dx071( [0,null,null,null,null,null,3,[["client","2"]]] )

當我加載其他KML文件時,此數據結構表示該文件中的數據。

一些事實:

  • 我的HTML文件和KML文件都在Amazon EC2實例上,並且可以公開訪問……沒有密碼,HTTPS或其他棘手的事務
  • 我的KML文件未壓縮...這是真實的真實KML文件
  • 我的KML文件在kmlvalidator.com上驗證
  • 我的KML大小為709K,其中包含多邊形
  • 沒有錯誤消息產生,除了地圖本身之外,地圖上什么也沒有出現。

感謝您能找出為什么未加載此KML層的任何幫助。

謝謝!

我遇到了同樣的問題(響應為空)。 原來我是通過服務器上的iptables阻止google的。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM