hussain hussain - 2 months ago 22
Swift Question

Change the Size of Marker in GoogleMap using Swift

I have placed a marker in

GoogleMap
which contains
Image
. but the size of image is much bigger. so how can i decrease the size of an marker. i have tried this :

marker.icon = self.image(marker.icon, scaledToSize: CGSize(width: 3.0, height: 3.0))

Answer

To resize the image refer to :The simplest way to resize an UIImage?

Now the set the resized image as marker icon ,i.e,

marker.icon = self.imageWithImage(image: UIImage(named: "imageName")!, scaledToSize: CGSize(width: 3.0, height: 3.0))

Edit:

func imageWithImage(image:UIImage, scaledToSize newSize:CGSize) -> UIImage{
    UIGraphicsBeginImageContextWithOptions(newSize, false, 0.0);
    image.drawInRect(CGRectMake(0, 0, newSize.width, newSize.height))
    let newImage:UIImage = UIGraphicsGetImageFromCurrentImageContext()
    UIGraphicsEndImageContext()
    return newImage
}