Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 853
Pangu Avatar asked Dec 25 '14 23:12

Pangu


People also ask

How do I add custom icons to Google Maps?

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.

How to remove marker from Google map iOS?

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.

How do you change the color of the Google Maps icon?

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.


2 Answers

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)];
like image 188
ztan Avatar answered Oct 22 '22 19:10

ztan


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];
like image 20
Hasan Sawaed Avatar answered Oct 22 '22 19:10

Hasan Sawaed