Resize Google Maps marker icon image

后端 未结 7 1580
感动是毒
感动是毒 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:26

    MarkerImage has been deprecated for Icon

    Until version 3.10 of the Google Maps JavaScript API, complex icons were defined as MarkerImage objects. The Icon object literal was added in 3.10, and replaces MarkerImage from version 3.11 onwards. Icon object literals support the same parameters as MarkerImage, allowing you to easily convert a MarkerImage to an Icon by removing the constructor, wrapping the previous parameters in {}'s, and adding the names of each parameter.

    Phillippe's code would now be:

     var icon = {
         url: "../res/sit_marron.png", // url
         scaledSize: new google.maps.Size(width, height), // size
         origin: new google.maps.Point(0,0), // origin
         anchor: new google.maps.Point(anchor_left, anchor_top) // anchor 
     };
    
     position = new google.maps.LatLng(latitud,longitud)
     marker = new google.maps.Marker({
      position: position,
      map: map,
      icon: icon
     });
    
    0 讨论(0)
提交回复
热议问题