.gif 标记谷歌地图 [英] .gif marker google maps

查看:35
本文介绍了.gif 标记谷歌地图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码中有这个

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
      });
    }
  }

但是标记没有出现,如果我使用 png 或 jpeg 它可以工作.我究竟做错了什么??gif 动画有其他处理吗?

but the marker doesn't appear and if I use a png or jpeg it works. What am I doing wrong?? Do the gif animations have another treatment?

推荐答案

作为标准,标记使用称为优化呈现的东西,始终将标记呈现为静态.要查看动画 gif,您需要在标记上设置优化 = false.用于生成标记的代码将是:

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. 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:

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

你应该删除).

这篇关于.gif 标记谷歌地图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆