为什么此 .kml 文件会在 zero/longitude 零纬度处加载?

Why does this .kml file load at latitude zero/longitude zero?

我手工创建了这个 .kml 文件,描绘了美国新罕布什尔州的一个区域。它在 Google MyMaps 中加载正常,但如果我在 Google Earth 中加载它,它显然被放置在“Null Island”(纬度 0,经度 0)。文件有什么问题?

<?xml version="1.0" encoding="UTF-8"?> 
<kml xmlns="http://earth.google.com/kml/2.0"> <Document>

<Placemark> 
 <LineString>
  <coordinates>
  -71.21122, 43.25277, 0.
  -71.20669, 43.24993, 0.
  -71.20720, 43.24918, 0.
  -71.20512, 43.24787, 0.
  -71.20566, 43.24733, 0.  
  -71.20576, 43.24718, 0.
  -71.20669, 43.24557, 0.
  -71.20763, 43.24572, 0.
  -71.20746, 43.24666, 0.
  -71.20855, 43.24638, 0.
  -71.20868, 43.24588, 0.
  -71.20961, 43.24596, 0.
  -71.21044, 43.24290, 0.
  -71.21673, 43.24390, 0.
  -71.21122, 43.25277, 0.
  </coordinates>
 </LineString>
</Placemark>

</Document> </kml>

谢谢

KML coordinates are longitude,latitude;不允许有空格。

您的 KML 应该是:

<?xml version="1.0" encoding="UTF-8"?> 
<kml xmlns="http://earth.google.com/kml/2.0"> <Document>

<Placemark> 
 <LineString>
  <coordinates>
  -71.21122,43.25277,0.
  -71.20669,43.24993,0.
  -71.20720,43.24918,0.
  -71.20512,43.24787,0.
  -71.20566,43.24733,0.  
  -71.20576,43.24718,0.
  -71.20669,43.24557,0.
  -71.20763,43.24572,0.
  -71.20746,43.24666,0.
  -71.20855,43.24638,0.
  -71.20868,43.24588,0.
  -71.20961,43.24596,0.
  -71.21044,43.24290,0.
  -71.21673,43.24390,0.
  -71.21122,43.25277,0.
  </coordinates>
 </LineString>
</Placemark>
</Document> </kml>

example displaying with the Google Maps Javascript API v3

代码片段:

function initMap() {
  const map = new google.maps.Map(document.getElementById("map"), {
    zoom: 11,
    center: {
      lat: 41.876,
      lng: -87.624
    },
  });
  const ctaLayer = new google.maps.KmlLayer({
    url: "http://www.geocodezip.com/geoxml3_test/kml/SO_20201106_removeSpaces.kml",
    map: map,
  });
}
/* Always set the map height explicitly to define the size of the div
       * element that contains the map. */

#map {
  height: 100%;
}


/* Optional: Makes the sample page fill the window. */

html,
body {
  height: 100%;
  margin: 0;
  padding: 0;
}
<!DOCTYPE html>
<html>

<head>
  <title>KML Layers</title>
  <script src="https://polyfill.io/v3/polyfill.min.js?features=default"></script>
  <script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyCkUOdZ5y7hMm0yrcCQoCvLwzdM6M8s5qk&callback=initMap&libraries=&v=weekly" defer></script>
  <!-- jsFiddle will insert css and js -->
</head>

<body>
  <div id="map"></div>
</body>

</html>