2012-11-15 40 views
1

我可以在Google地球上顯示KML。 現在我想在地圖上顯示相同的內容.. 這怎麼可能? 這裏是我的KML附...在Google地圖上使用KML及其名稱顯示多邊形或圓形

<?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> 

在此先感謝..

+0

你要顯示它在什麼地圖?[谷歌地圖}(http://maps.google.com)?還是谷歌Maps API v3地圖?對於您的KML而言,必須在公開的網站上發佈。 – geocodezip

回答

0

要在谷歌地圖顯示KML,它需要一個公開訪問的Web服務器上。

然後要麼使用谷歌地圖API V3 KmlLayerGoogle Maps

Google Maps API v3 KmlLayer example from the documentation

代碼以顯示KML文件:

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是在谷歌地圖顯示相同的KML文件。

UPDATE:

http://www.geocodezip.com/geoxml3_test/Point_Placemarks.Descriptive_HTML_kml.xml">Here是使用谷歌地圖API V3顯示從您的評論文件的本地副本geoxml3第三方解析器 (KmlLayer似乎認爲這是一個無效的文件)

Here is that KML displayed on Google Maps

+0

http:// kml-s amples.googlecode.com/svn/trunk/interactive/index.html#./Point_Placemarks/Point_Placemarks.Descriptive_HTML.kml 在此鏈接中,粘貼上面所述的KML代碼。在放置代碼後,Google地球顯示點名稱,但同樣無法使用api v3在谷歌地圖上顯示。 –

相關問題