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?
For adding a custom marker to Google Maps navigate to the app > res > drawable > Right-Click on it > New > Vector Assets and select the icon which we have to show on your Map. You can change the color according to our requirements. After creating this icon now we will move towards adding this marker to our Map.
You can remove a marker from the map by setting the map property of the GMSMarker to nil . Alternatively, you can remove all of the overlays (including markers) currently on the map by calling the GMSMapView clear method.
Click on the option labeled Tools and then click on Change map. Once there, click on the button labeled Change feature styles. There are plenty of options for changing the different styles of your markers, which includes changing their color.
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)];
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];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With