带有弹跳标记的Google地图

时间:2015-11-25 19:19:51

标签: javascript google-maps google-maps-markers

我正在尝试使用Google API3获取带有弹跳标记的Google地图。我的代码如下。

到目前为止,我无法做到的事情如下:

  1. 标记连续弹跳;我需要它反弹一次。
  2. 我需要禁用鼠标滚轮移动以进行缩放。
  3. 我想将地图的颜色更改为浅蓝色。
  4. <!DOCTYPE html>
    <html> 
    <head> 
      <meta http-equiv="content-type" content="text/html; charset=UTF-8" /> 
      <title>Google Map with Marker</title> 
      <script src="http://maps.google.com/maps/api/js?sensor=false" 
              type="text/javascript"></script>
    </head> 
    <body>
      <div id="map" style="width: 500px; height: 400px;"></div>
    
      <script type="text/javascript">
        var locations = [
         ['Maroubra Beach', -33.950198, 151.259302, 1]
        ];
    
        var map = new google.maps.Map(document.getElementById('map'), {
          zoom: 10,
          center: new google.maps.LatLng(-33.92, 151.25),
          mapTypeId: google.maps.MapTypeId.ROADMAP
        });
    
        var infowindow = new google.maps.InfoWindow();
    
        var marker, i;
    
        for (i = 0; i < locations.length; i++) {  
          marker = new google.maps.Marker({
            position: new google.maps.LatLng(locations[i][1], locations[i][2]),
            map: map
          });
    
    
    marker.setAnimation(google.maps.Animation.BOUNCE);
    
          google.maps.event.addListener(marker, 'click', (function(marker, i) {
            return function() {
              infowindow.setContent(locations[i][0]);
              infowindow.open(map, marker);
            }
          })(marker, i));
        }
      </script>
    </body>
    </html>
    

    如果有人能指出我正确的方向,我会非常感激。

2 个答案:

答案 0 :(得分:1)

对于第一个问题,您可以简单地使用基于ond timeout的setAnimation函数

marker.setAnimation(google.maps.Animation.BOUNCE);
setTimeout(function(){ marker.setAnimation(null); }, 1000);

这种方式反弹一秒钟,你可以调整你喜欢的持续时间

答案 1 :(得分:1)

对于第二个问题,您可以在选项中将相关选项滚轮设置为false,例如:

var mapOptions = {
            center: new google.maps.LatLng(54.9000, 25.3167),
            zoom: 4,
           scrollwheel: false,
            mapTypeId: google.maps.MapTypeId.ROADMAP
        }