1

让我们从我不知道自己在做什么开始。在此之前没有真正做过任何js。我尝试让标记在它们之间稍有延迟地下降。我已经完成了我的研究并尝试了几篇文章,但我无法让它们发挥作用。这是我的代码:

<html>
  <head>
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
    <style type="text/css">
      html { height: 100% }
      body { height: 100%; margin: 0; padding: 0 }
      #map-canvas { height: 100% }
    </style>
    <script type="text/javascript"
      src="https://maps.googleapis.com/maps/api/js?key=KEY&sensor=false">
    </script>
    <script type="text/javascript">
      function initialize() {
        var mapOptions = {
          center: new google.maps.LatLng(52.365642,5.181599),
          zoom: 13,
          zoomControl: false,
          scaleControl: false,
          scrollwheel: false,
          disableDoubleClickZoom: true,
          disableDefaultUI: true,
          mapTypeId: google.maps.MapTypeId.ROADMAP,

          styles: [{"stylers":[{ "saturation": -29 },{ "visibility": "simplified" }]},
          {"elementType": "labels", "stylers": [{ "visibility": "off" }]}]
        }; 

        var map = new google.maps.Map(document.getElementById("map-canvas"),
            mapOptions);

        setMarkers(map, locaties);
      }

      var locaties = [
        ['Bondi en zo', 52.365642, 5.181599],
        ['Coogee en zo', 52.365642, 5.182599],
        ['Cronulla en zo', 52.365642, 5.183599],
        ['Manly en zo', 52.365642, 5.184599],
        ['Maroubra en zo', 52.365642, 5.185599]
      ];


      function drop() {
        for (var i =0; i < locaties.length; i++) {
          setTimeout(function() {
            setMarkers();
          }, i * 200);
        }
      }

      function setMarkers(map, locations) {

        for (var i = 0; i < locations.length; i++) {
          var klant = locations[i];
          var myLatLng = new google.maps.LatLng(klant[1], klant[2]);
          var marker = new google.maps.Marker({
              position: myLatLng,
              map: map,
              animation: google.maps.Animation.DROP
          });
        }
      }

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

ps,是的,我已经改变了密钥

4

1 回答 1

3

Change your functions like this, now the drop function creates a interval and drops the marker and your setMarkers function iterates the locations and calls drop function

      function drop(map, myLatLng) {
          setTimeout(function() {
            var marker = new google.maps.Marker({
              position: myLatLng,
              map: map,
              animation: google.maps.Animation.DROP
            });
          }, i * 200);
      }

      function setMarkers(map, locations) {
        for (var i = 0; i < locations.length; i++) {
          var klant = locations[i];
          var myLatLng = new google.maps.LatLng(klant[1], klant[2]);
          drop(map, myLatLng);
        }
      }

PS: please dont just copy paste code from here and there, understand first what they are trying to explain and thanks for changing the key ;)

于 2013-03-26T05:31:48.060 回答