javascript 修改我的 Google 地图的自定义标记图像大小

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/32062849/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-28 14:47:45  来源:igfitidea点击:

Modify my custom marker image size for my Google Map

javascriptgoogle-mapsgoogle-maps-api-3google-maps-markers

提问by user1186050

I have a custom image (512 x 512) If I use this image maps doesn't render it because it's too big. I have to shrink the size of the image down. I want to make it about 22 x 32, which is about the size of an icon. I can shrink the image down on my desktop using MS Paint or Paint Shop Pro, but when I open it in maps it looks blurry. Some of the quality has been degraded.

我有一个自定义图像 (512 x 512) 如果我使用这个图像映射不会渲染它,因为它太大了。我必须缩小图像的大小。我想让它大约为 22 x 32,大约是一个图标的大小。我可以使用 MS Paint 或 Paint Shop Pro 在我的桌面上缩小图像,但是当我在地图中打开它时,它看起来很模糊。部分质量已经下降。

  1. Is there a way to set the size in the marker options so I can still use the original image?
  2. If not, does anyone know how to shrink an image without loosing quality?'
  1. 有没有办法在标记选项中设置大小,以便我仍然可以使用原始图像?
  2. 如果没有,有谁知道如何在不降低质量的情况下缩小图像?

I tried setting the size in the code below but nothing gets rendered on the map.

我尝试在下面的代码中设置大小,但地图上没有渲染任何内容。

var image = {
        url: '/Images/orange_guy.png', // image is 512 x 512
        size: new google.maps.Size(22, 32),     
    }; 

    var marker = new google.maps.Marker({
        position: { lat: location.Lat, lng: location.Long },
        map: map,
        icon: image
    });

回答by Ivan Jovovi?

Use scaledSizeinstead of size:

使用scaledSize代替size

var image = {
        url: '/Images/orange_guy.png', // image is 512 x 512
        scaledSize : new google.maps.Size(22, 32)
    };

Working fiddle:

工作小提琴:

http://jsfiddle.net/4mtyu/556/

http://jsfiddle.net/4mtyu/556/