1

我是 Google 地球的新手。我正在尝试开发一个应用程序来可视化地图上的天气数据。这是可以在本地 GE 上运行的简单代码(我只是从其他地方复制了一个示例)

<?xml version="1.0" encoding="utf-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
  <Document>
    <Style id="s1">
      <LineStyle>
        <color>7f0000ff</color>
        <width>4</width>
      </LineStyle>
      <PolyStyle>
        <color>7f0000ff</color>
        <colorMode>normal</colorMode>
        <fill>1</fill>
        <outline>1</outline>
      </PolyStyle>
    </Style>

    <name>All isolation countries</name>
    <description>All isolation countries</description>
    <Placemark>
      <styleUrl>#s1</styleUrl>
      <name>Indonesia</name>
    </Placemark>
    <Placemark>
      <styleUrl>#s1</styleUrl>
      <name>Ecuador</name>
      <Polygon>
      <tessellate>1</tessellate>
        <extrude>1</extrude>
        <altitudeMode>clampedToGround</altitudeMode>
        <outerBoundaryIs>
          <LinearRing>
            <coordinates>-90.61167907714844,-0.3755556046962738,0 -90.77166748046875,-0.344166785478592,0 -90.87222290039063,-0.2652778923511506,0 -90.79332733154297,-0.149444505572319,0 -90.77362060546876,-0.1550000011920929,0 -90.58556365966797,-0.2455555945634842,0 -90.55029296875,-0.3091666996479035,0 -90.61167907714844,-0.3755556046962738,0</coordinates>
          </LinearRing>
        </outerBoundaryIs>

      </Polygon>
    </Placemark>
    </Document>
    </kml>

这是我在 HTML 中集成的代码

<html>
<head>
  <title>Sample</title>
  <script type="text/javascript" src="https://www.google.com/jsapi"> </script>
  <script type="text/javascript">
    var ge;
    var placemark;
    var object;

    google.load("earth", "1");

    function init() {
      google.earth.createInstance('map3d', initCB, failureCB);
    }

    function initCB(instance) {
      ge = instance;
      ge.getWindow().setVisibility(true);


     var kmlString = ''
     + '<?xml version="1.0" encoding="UTF-8"?>'
     + '<kml xmlns="http://www.opengis.net/kml/2.2">'
     + '<Document>'
     + ' <Style id="s1">'
     + ' <LineStyle>'
     + '  <color>7f0000ff</color>'
       + ' <width>4</width>'
      +'</LineStyle>'
     +' <PolyStyle>'
      +'  <color>7f0000ff</color>'
       +' <colorMode>normal</colorMode>'
       +' <fill>1</fill>'
       +' <outline>1</outline>'
     +' </PolyStyle>'
    +'</Style>'
    +'<name>All isolation countries</name>'
    +'<description>All isolation countries</description>'
    +'<Placemark>'
     +' <styleUrl>#s1</styleUrl>'
     +' <name>Indonesia</name>'
    +'</Placemark>'
    +'<Placemark>'
     +' <styleUrl>#s1</styleUrl>'
      +'<name>Ecuador</name>'
      +'<Polygon>'
      +'<tessellate>1</tessellate>'
        +'<extrude>1</extrude>'
        +'<altitudeMode>clampedToGround</altitudeMode>'
        +'<outerBoundaryIs>'
          +'<LinearRing>'
            +'<coordinates>-90.61167907714844,-0.3755556046962738,0 -90.77166748046875,-0.344166785478592,0 -90.87222290039063,-0.2652778923511506,0 -90.79332733154297,-0.149444505572319,0 -90.77362060546876,-0.1550000011920929,0 -90.58556365966797,-0.2455555945634842,0 -90.55029296875,-0.3091666996479035,0 -90.61167907714844,-0.3755556046962738,0</coordinates>'
          +'</LinearRing>'
        +'</outerBoundaryIs>'
     +' </Polygon>'
    +'</Placemark>'
                         + '</Document>'
                         + '</kml>';

         var kmlObject = ge.parseKml(kmlString);
         ge.getFeatures().appendChild(kmlObject);
         ge.getView().setAbstractView(kmlObject.getAbstractView());
    }

    function failureCB(errorCode) {
    }

    google.setOnLoadCallback(init);
  </script>

</head>
<body>
  <div id="map3d" style="height: 400px; width: 600px;"></div>
</body>
</html>

谁能给我一些想法?另外,我需要大量的纬度、经度和高度的数据输入,有没有办法读取这些文件?

4

2 回答 2

1

JavaScript Maps API 将接受来自可公开访问的 URL 的 KML - 您不能传入字符串/文件。如果您需要使用本地 KML 文件,您必须自己解析 KML 并使用 Google Maps API 创建形状。在此处查看这篇出色的帖子:Google Maps API 和 KML File LocalHost Development Options

于 2013-01-22T15:44:05.373 回答
0

正如 Matthew 所说,Google 地图需要使用远程 URI 来获取您的 KML:将其保存为具有公共 URI 的文件。

GeoXML3可以读取和映射 KML,并且不受此限制。

于 2014-02-19T07:43:59.037 回答