Pangu
Pangu

Reputation: 3819

How to resize a GMSMarker icon in Google Maps for iOS?

I am using Google Maps SDK in xCode and trying to scale a marker icon to make it bigger on the mapView.

I am trying to do something like this:

marker.icon.scale = 3.0f;

But it gives me a:

assignment to readonly property error

Obviously since it's readonly, I cannot write to it.

Therefore, is there an alternative to be able to resize or scale my marker icon?

Upvotes: 6

Views: 14807

Answers (3)

Ted
Ted

Reputation: 23746

You can create

CGRect frame = CGRectMake(0, 0, 10, 10);
UIImageView *imageView = [[UIImageView alloc] initWithFrame:frame];
imageView.image = [UIImage imageNamed:@"yourImage"];

then assign it to marker

marker.iconView = imageView;

Upvotes: 0

Hasan Sawaed
Hasan Sawaed

Reputation: 173

you can covert the image to NSData

NSData *imageData = [NSData dataWithContentsOfFile:imagePath];

and then use UIImage API method imageWithData:scale: , you can change your icon to any scale you want:

marker.icon = [UIImage imageWithData:imageData scale:2.0];

Upvotes: 3

ztan
ztan

Reputation: 6921

If you want to change the size of your icon which is an UIImage programmatically, you can implement a custom method to change your UIImage to your desired scale.

You can try the method from this answer.

After you implement that method in your code, you can do the following to change your icon (because marker.icon is writable):

marker.icon = [self image:marker.icon scaledToSize:CGSizeMake(3.0f, 3.0f)];

Upvotes: 13

Related Questions