Is there a way to change Google Maps Android API v2 marker’s icon during runtime without removing/re-adding the marker I want to change its icon? Can I apply transformations to it (like rotation)?
Thanks.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Currently you can’t change the marker at runtime, neither apply rotation to it.
You can use a workaround though – I’m working on a BlinkingMarker class where I have to adjust the opacity of the marker image at runtime.
The only solution right now is to create Bitmaps with different rotation and then add/remove them periodically. The problem with this solution is that adding/removing markers takes a lot of memory allocation so it results in constant garbage collection. A better and smoother workaround is to create all your images up-front and add all of them to the map at once. After that you can use the
Marker.setVisible(boolean)function to display the one that you currently need.Caution: measure your bitmaps before you do this, because adding a lot of big bitmaps can cause your app’s memory size to grow very big.
You can look at my workaround here:
https://github.com/balazsbalazs/blinking-marker-mapsv2
This is marker which is blinking (changes the opacity of the bitmap) but on the same lines you can apply any kind of transformation.