Google Maps API v3 drop markers from XML with delay?

前端 未结 1 655
既然无缘
既然无缘 2020-12-22 02:13

I\'m working on displaying several batches of markers using the Google Maps api (v3) and jQuery.

I\'ve got it working almost exactly as I want it but I would need to

相关标签:
1条回答
  • 2020-12-22 02:53

    How about this:

    jeMap.placeMarkers = function (filename) {
        //setup counter variable
        var counter = 0;
        $.get(filename, function (xml) {
            $(xml).find("marker").each(function () {
                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));
    
                //set timeout based on maps example
                setTimeout(function() {
                    addMarker(point, address, name);
                }, counter * 200);
    
                //increment counter
                counter++;            
            });
        });
    }
    
    //add marker with specific point.
    function addMarker(point, address, name){
        var marker = new google.maps.Marker({
            map: jeMap.map,
            position: point,
            animation: google.maps.Animation.DROP,
            icon: 'marker_pink.png'
        });
    
        var html = '<strong>' + name + '</strong.><br />' + address;
        google.maps.event.addListener(marker, 'click', function () {
            infoWindow.setContent(html);
            infoWindow.open(jeMap.map, marker);
        });
    }
    
    0 讨论(0)
提交回复
热议问题