简体   繁体   English

.gif标记谷歌地图

[英].gif marker google maps

I have in my code this 我的代码中有这个

var map;
  function initialize() {
    var mapDiv = document.getElementById('map-canvas');
    map = new google.maps.Map(mapDiv, {
      center: new google.maps.LatLng(37.4419, -122.1419),
      zoom: 13,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    });

    google.maps.event.addListenerOnce(map, 'tilesloaded', addMarkers);

  }

  function addMarkers() {
    var iconoMarca = "/assets/giftRayo.gif");       
    var bounds = map.getBounds();
    var southWest = bounds.getSouthWest();
    var northEast = bounds.getNorthEast();
    var lngSpan = northEast.lng() - southWest.lng();
    var latSpan = northEast.lat() - southWest.lat();
    for (var i = 0; i < 10; i++) {
      var latLng = new google.maps.LatLng(southWest.lat() + latSpan * Math.random(),
                                          southWest.lng() + lngSpan * Math.random());
      var marker = new google.maps.Marker({
        position: latLng,
        map: map,
        icon: iconoMarca
      });
    }
  }

but the marker doesn't appear and if I use a png or jpeg it works. 但是标记没有出现,如果我使用png或jpeg它可以工作。 What am I doing wrong?? 我究竟做错了什么?? Do the gif animations have another treatment? GIF动画有另外一种治疗方法吗?

As a standard, the markers use something called optimized rendering that always renders the markers as static. 作为标准,标记使用称为优化渲染的东西,始终将标记呈现为静态。 To see animated gifs you need to set optimized = false on your marker. 要查看GIF动画,您需要在标记上设置optimized = false。 The code for generating your marker would then be: 生成标记的代码将是:

var marker = new google.maps.Marker({
    position: latLng,
    map: map,
    icon: iconoMarca,
    optimized: false
  });

This should solve your problem. 这应该可以解决您的问题。

Ps.: You seem to have a small bug in your code: Ps。:您的代码中似乎有一个小错误:

var iconoMarca = "/assets/giftRayo.gif");  

You should remove the ). 你应该删除)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM