简体   繁体   English

将 kml 链接到 Google Maps Javascript API 不起作用

[英]Linking kml to Google Maps Javascript API not working

I'm trying to create a map with pins, it'll end up having hundreds of pins but for now I'm trying with just a few but I can't get it to work.我正在尝试使用图钉创建地图,最终会有数百个图钉,但现在我只尝试使用几个图钉,但无法使其正常工作。 I've tried a lot of different ways of linking it and none of them show.我尝试了很多不同的链接方式,但没有一个显示出来。

I think the problem could be the URL I'm using my own server, do I need a diferrent one?我认为问题可能是我使用自己的服务器的 URL,我需要一个不同的吗?

I've tried placing the kml on GitHub and the using that URL, that did not work either.我试过将 kml 放在 GitHub 上并使用该 URL,但也没有用。

     var kml_map = new google.maps.Map(document.getElementById('map_div'), mapOptions); 
  var kml_layer = new google.maps.KmlLayer({
          preserveViewport: true,
         url: 'http://zaguan.upc.es/web/movilidad/vitrina/map/etsab.kml'
   }); 
  kml_layer.setMap(kml_map);

    //map.data.loadGeoJson('http://zaguan.upc.es/web/movilidad/vitrina/map/data.json');
    //var ctaLayer = new google.maps.KmlLayer({
    //url: 'http://zaguan.upc.es/web/movilidad/vitrina/map/etsab.kml'
    //});
    //ctaLayer.setMap(map);

    //google.maps.event.addListener(kmlLayer, "status_changed", function() {
 //  document.getElementById('kmlstatus').innerHTML = "Kml Status:"+kmlLayer.getStatus();
// });
    //var ctaLayer = new google.maps.KmlLayer({
        //url: 'http://zaguan.upc.es/web/movilidad/vitrina/map/etsab.kml',
       // map: map
     // });

     //var layer = new google.maps.KmlLayer(kmlPath + '?' + urlSuffix );
    //layer.setMap(map);

        //var ctaLayer = new google.maps.KmlLayer({
        //url: 'http://zaguan.upc.es/web/movilidad/vitrina/map/etsab.kml'
        //});
    //ctaLayer.setMap(map);

I'm certain the kml works because I can open it on Google Earth and I'll see the pins.我确定 kml 可以工作,因为我可以在 Google 地球上打开它,我会看到图钉。

Here's the kml I'm using:这是我正在使用的kml:

<?xml version='1.0' encoding='UTF-8'?>
<kml xmlns='http://www.opengis.net/kml/2.2'>
    <Document>
        <name>Mobilitat ETSAB</name>
        <description><![CDATA[Programa de mobilitat ETSAB curs 2013/14]]></description>
        <Folder>
            <name>Etsab Mobilitat</name>
            <Placemark>
                <name>EtsaB</name>
                <styleUrl>#icon-123-nodesc</styleUrl>
                <Point>
                    <coordinates>2.1140388999999686,41.38406519999999,0.0</coordinates>
                </Point>
            </Placemark>
            <Placemark>
                <name>Technische Universität Berlin Institut für Architektur</name>
                <styleUrl>#icon-123-nodesc</styleUrl>
                <Point>
                    <coordinates>13.323496299999988,52.51379379999999,0.0</coordinates>
                </Point>
            </Placemark>
            <Placemark>
                <name>Technische Universität Darmstadt Fachbereich Architektur</name>
                <styleUrl>#icon-123-nodesc</styleUrl>
                <Point>
                    <coordinates>8.676702699999964,49.861146500000004,0.0</coordinates>
                </Point>
            </Placemark>
            <Placemark>
                <name>Leibniz Universität Hannover - Fakultät für Architektur und Landschaft</name>
                <styleUrl>#icon-123-nodesc</styleUrl>
                <Point>
                    <coordinates>9.695992,52.393044,0.0</coordinates>
                </Point>
            </Placemark>
        </Folder>

        <Style id='icon-123-nodesc-normal'>
            <IconStyle>
                <scale>1.1</scale>
                <Icon>
                    <href>http://www.gstatic.com/mapspro/images/stock/123-red-dot.png</href>
                </Icon>
                <hotSpot x='16' y='31' xunits='pixels' yunits='insetPixels'>
                </hotSpot>
            </IconStyle>
            <LabelStyle>
                <scale>0.0</scale>
            </LabelStyle>
            <BalloonStyle>
                <text><![CDATA[<h3>$[name]</h3>]]></text>
            </BalloonStyle>
        </Style>

    </Document>

</kml>

The problem was that I was using the wrong server.问题是我使用了错误的服务器。 Thanks Dr.Molle!谢谢莫尔医生!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM