6

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?

Pangu
  • 3,721
  • 11
  • 53
  • 120

3 Answers3

13

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)];
Community
  • 1
  • 1
ztan
  • 6,861
  • 2
  • 24
  • 44
3

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];
Hasan Sawaed
  • 173
  • 2
  • 9
0

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;
Ted
  • 22,696
  • 11
  • 95
  • 109