首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >在Google地图上使用KML及其名称显示面或圆

在Google地图上使用KML及其名称显示面或圆
EN

Stack Overflow用户
提问于 2012-11-15 13:04:32
回答 1查看 1.6K关注 0票数 1

我可以在谷歌地球上显示KML。现在我想在地图上显示相同的内容。这怎么可能呢?这是我的KML附件。

代码语言:javascript
运行
复制
<?xml version="1.0" encoding="UTF-8"?> <kml xmlns="http://www.opengis.net/kml/2.2">
  <Document>
    <name>Hide and show labels</name>
    <Style id="sn_hide">
      <IconStyle>
        <scale>0</scale>
      </IconStyle>
    </Style>

    <StyleMap id="msn_hide">
      <Pair>
        <key>normal</key>
        <styleUrl>#sn_hide</styleUrl>
      </Pair>      
    </StyleMap>
    <Placemark>
      <name>Placemark 1</name>
      <description>Label hidding</description>
      <styleUrl>#sn_hide</styleUrl>
      <Point>
        <coordinates>-119.232195,36.016021</coordinates>
      </Point>
    </Placemark>
    <Placemark>
      <name>Placemark 2</name>
      <description>Label hidding</description>
      <styleUrl>#sn_hide</styleUrl>
      <Point>
        <coordinates>-119.232195,36.0162</coordinates>
      </Point>
    </Placemark>

  </Document>
</kml>

提前谢谢..​

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-11-15 13:57:36

要在Google Map上显示KML,它需要位于可公开访问的web服务器上。

然后使用Google Maps API v3 KmlLayerGoogle Maps

Google Maps API v3 KmlLayer example from the documentation

显示KML文件的代码:

代码语言:javascript
运行
复制
    var chicago = new google.maps.LatLng(41.875696,-87.624207);
    var mapOptions = {
      zoom: 11,
      center: chicago,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    }

    var map = new google.maps.Map(document.getElementById('map_canvas'), mapOptions);

    var ctaLayer = new google.maps.KmlLayer('http://gmaps-samples.googlecode.com/svn/trunk/ggeoxml/cta.kml');
    ctaLayer.setMap(map);

Here与Google Maps上显示的KML文件相同。

更新:

Here">http://www.geocodezip.com/geoxml3_test/Point_Placemarks.Descriptive_HTML_kml.xml">Here是使用Google Maps API v3 geoxml3第三方解析器显示的评论中的文件的本地副本(KmlLayer似乎认为它是一个无效文档)

Here is that KML displayed on Google Maps

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13391825

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档