简体   繁体   中英

JavaScript Parsing Outside XML/KML - Geoxml3

I have implemented a script that parses KML into a Google map, as described here. There's also a working sample here.

This works great in Safari and IE, but nothing happens in Firefox or Chrome on my installation (still local) and on the demo site. The only thing in the log is this:

--[13:07:38.076] "Unable to retrieve station.kml"

Could someone take a look at this and shed some light? I'm not proficient enough in JavaScript to figure out what's going on.

Thanks!

UPDATE: Here's my actual code.

<!DOCTYPE html>
<html class="no-js" lang="en"> <!--<![endif]-->
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <title>Where Are Our Alumni?</title>
    <meta name="description" content="">
    <meta name="viewport" content="width=device-width">

    <style type="text/css">
    body, html {
      height: 100%;
      width: 100%;
      margin: 0;
      padding: 0; 
    }

    div#map-canvas {
      width: 100%; height: 100%;
    }
    </style>

    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
    <script src="geoxml3.js"></script>
    <script src="markerclusterer.js"></script>
    <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>


    <script type="text/javascript" charset="utf-8">
      $(document).ready(function(){
    var myOptions = {
          center: new google.maps.LatLng(41.8813571,-87.6294174),
          zoom: 3,
          mapTypeId: google.maps.MapTypeId.ROADMAP
        };
        var mcOptions = {gridSize: 50, maxZoom: 15};
        var weather_url = "http://api.wunderground.com/api/6d9cb153ba3be6c0/conditions/forecast/q/";
        var count = 0;
        markers = [];
        var map = new google.maps.Map(document.getElementById("map-canvas"), myOptions);
        markerclusterer  = new MarkerClusterer(map, [], mcOptions);
        var infoWindow = new google.maps.InfoWindow({maxWidth:800});
        var myParser = new geoXML3.parser({
        map: map, singleInfoWindow:true,
        createMarker:function(placemark){
                if (placemark.point.lat != '0') {
                var point = new google.maps.LatLng(placemark.point.lat, placemark.point.lng);
                var marker = new google.maps.Marker({position:point});
                markers.push(marker);

                google.maps.event.addListener(marker, "click", function(){
                    var marker_lat = marker.getPosition().lat();
                    var marker_lng = marker.getPosition().lng();
                    var request_url = weather_url + (marker_lat + "," + marker_lng);
                    infoWindow.close(); 
                    infoWindow.setOptions({maxWidth:800});
                    content = ("<div><strong>" + placemark.name + "</strong><br>");
                    content += (placemark.description + "</div>");
                    infoWindow.setContent(content);
                    infoWindow.open(map, marker);


                });
                markerclusterer.addMarker(marker);
        }
    }
    });
        myParser.parse('alumni.kml');
      });

      function clickMarker(i){
             google.maps.event.trigger(markers[i], "click");
      }
    </script>
</head>
<body>

    <div id="map-canvas"></div>


</body>
</html>

The geoxml3.js script is what's causing the error, available from here.

Looks like you are using an old version of geoxml3 . You should use the latest version from the polys branch , unless you need KMZ support, in which case, use the latest version from the kmz branch .

Working example of clustered markers from KML with geoxml3

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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