Modify my custom marker image size for my Google M

2019-07-23 00:01发布

问题:

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/