0

好的,所以我开发了以下代码以将 Google Maps 与 Marker Clusterer 一起使用。我使用了网站上的示例,并针对我的 json 数据稍作修改。我的问题是,我没有收到任何错误,但它也不起作用。我在这里做错了什么?

谢谢

<head>
    <style type="text/css">
        body {
            margin: 0;
            padding: 10px 20px 20px;
            font-family: Arial;
            font-size: 16px;
        }

        #map-container {
            padding: 6px;
            border-width: 1px;
            border-style: solid;
            border-color: #ccc #ccc #999 #ccc;
            -webkit-box-shadow: rgba(64, 64, 64, 0.5) 0 2px 5px;
            -moz-box-shadow: rgba(64, 64, 64, 0.5) 0 2px 5px;
            box-shadow: rgba(64, 64, 64, 0.1) 0 2px 5px;
            width: 600px;
        }

        #map {
            width: 600px;
            height: 400px;
        }
    </style>

    <script src="http://maps.google.com/maps/api/js?sensor=false"></script>
    <script src="http://google-maps-utility-library-v3.googlecode.com/" +
        "svn/trunk/markerclusterer/src/markerclusterer.js">
    </script>

    <script type="text/javascript">
        var data = {
            "users": [ 
                { "latitude":"48.4048403957642",
                    "longitude":"2.68452644348145" },
                { "latitude":"48.4050236871384",
                    "longitude":"2.68512690051361"},
                { "latitude":"48.4048403957642",
                    "longitude":"2.68452644348145"},
                { "latitude":"48.7570941168018",
                    "longitude":"2.16670989990234"},
                { "latitude":"48.404922961092",
                    "longitude":"2.70020564018949"},
                { "latitude":"48.8739279353421",
                    "longitude":"2.32875823974609"},
                { "latitude":"48.4048403957642",
                    "longitude":"2.68452644348145"},
                { "latitude":"41.0349860434783",
                    "longitude":"28.9774059609177"}
            ]
        };

        function initialize() {
            var center =
                new google.maps.LatLng(48.404840395764175,
                    2.6845264434814453);

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

            var markers = [];
            for (var i = 0; i < data.length; i++) {
                var location = data.users[i];
                var latLng =
                    new google.maps.LatLng(location.latitude,
                        location.longitude);
                var marker = new google.maps.Marker({ position: latLng });
                markers.push(marker);
            }

            var markerCluster = new MarkerClusterer(map, markers);
        }

        google.maps.event.addDomListener(window, 'load', initialize);
    </script>  
</head>
<body>
    <div id="map-container"><div id="map"></div></div>
4

1 回答 1

0

没有添加标记,因为

for (var i = 0; i < data.length; i++) {

应该

for (var i = 0; i < data.users.length; i++) {

于 2012-05-28T13:40:20.543 回答