Resize Google Maps marker icon image

后端 未结 7 1602
感动是毒
感动是毒 2020-11-29 17:41

When I load an image into the icon property of a marker it displays with its original size, which is a lot bigger than it should be.

I want to resize to the standard

7条回答
  •  心在旅途
    2020-11-29 18:07

    If the original size is 100 x 100 and you want to scale it to 50 x 50, use scaledSize instead of Size.

    var icon = {
        url: "../res/sit_marron.png", // url
        scaledSize: new google.maps.Size(50, 50), // scaled size
        origin: new google.maps.Point(0,0), // origin
        anchor: new google.maps.Point(0, 0) // anchor
    };
    
    var marker = new google.maps.Marker({
        position: new google.maps.LatLng(lat, lng),
        map: map,
        icon: icon
    });
    

提交回复
热议问题