Modify my custom marker image size for my Google Map

可紊 提交于 2019-12-11 03:34:59

问题


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.

  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?'

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

回答1:


Use scaledSize instead of 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/



来源:https://stackoverflow.com/questions/32062849/modify-my-custom-marker-image-size-for-my-google-map

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!