Google Maps Marker Clustering - markerclusterPlus

时间:2012-01-10 09:30:32

标签: javascript google-maps-api-3 markerclusterer

基于xml文件,我想在地图上设置markerclusterer。

我使用markerclusterPlus版本3! http://google-maps-utility-library-v3.googlecode.com/svn/trunk/markerclusterer/

问题是,没有标记会显示,我不知道为什么

markers.xml

<?xml version="1.0"?>
<markers>
    <marker>
        <name>Heineken Amsterdam</name>
        <address>Joop Geesinkweg 5</address>
        <city>Amsterdam</city>
        <postcode>1096 AT</postcode>
        <lat>52.3354</lat>
        <lng>4.92938</lng>
         </marker>
</markers>

的index.php

<html>
<head>
<title>Google Maps Integration</title>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript" src="js/jquery-1.4.1.min.js"></script>
<script type="text/javascript" src="js/markerclusterer.js"></script>
<style type="text/css">
#map {
      width: 675px;
      height: 659px;
      }
</style>
<script type="text/javascript">
function initialize() {
        var filename = "markers.xml";
        var center = new google.maps.LatLng(51.918, 4.47663);

        var map = new google.maps.Map(document.getElementById('map'), {
          zoom: 7,
          center: center,
          mapTypeId: google.maps.MapTypeId.ROADMAP
        });

        var markers = []; // array markers
        $.get(filename, function(xml){
            $(xml).find("marker").each(function(){ // get each marker position
                var name = $(this).find('name').text();
                var address = $(this).find('address').text();
                // create a new LatLng point for the marker
                var lat = $(this).find('lat').text();
                var lng = $(this).find('lng').text();
                var point = new google.maps.LatLng(parseFloat(lat),parseFloat(lng));
                var marker = new google.maps.Marker({
                    position: point,
                    map: null,
                    html: '<b>'+name+'</b><br>'+address
                });     

                markers.push(marker); // push marker to markers array
            });
        });
        var markerCluster = new MarkerClusterer(map, markers); // create marker clusterer
      }
google.maps.event.addDomListener(window, 'load', initialize);
</script>
</head>
<body>
<div id="map"></div>
</body>
</html>

1 个答案:

答案 0 :(得分:0)

尝试在$(xml).find(“marker”)之前插入这一行。each(function():

 var xml = parseXml("<div>" + xml + "</div>");