2

I have some pin graphic for my markers, but i have to rotate them. I googled alot but just coudnt find the solution.

Is there anybody know how could i achive this somehow ?

BitmapDescriptor does not have any functions like this, nor have MarkerOptions or Marker itself.

Please suggest me some ways.

Adam Varhegyi
  • 12,015
  • 32
  • 115
  • 205
  • Not sure if this is the best way but since your pin is a drawable you can draw it rotated on a canvas. Afterwards you get the bitmap with the pin rotated and set it as icon the the marker (you should hold a reference to the marker). Please check the accepted answer from here http://stackoverflow.com/questions/13991301/android-maps-api-v2-draw-circle – Ungureanu Liviu Jul 10 '13 at 12:43

2 Answers2

3

In a new maps api (revision 7 of API v2) new method called setIcon (BitmapDescriptor icon) was added you can try it after update - it must work flawlessly. https://developers.google.com/maps/documentation/android/reference/com/google/android/gms/maps/model/Marker#setIcon%28com.google.android.gms.maps.model.BitmapDescriptor%29

But if you don't want to update then the only way to do this is changing marker icon at runtime (dynamically) but as was said here https://developers.google.com/maps/documentation/android/marker: You can't change the icon once you've created the marker. So the only way is dynamically recreate marker.This is a bad solution because recreating markers takes a lot of memory allocation so it results in garbage collection and performance drawbacks. In order to avoid this create all your marker bitmaps and add all of them to the map at once. After that you can use Marker.setVisible(boolean) function to display the one that you currently need.

Oleksandr Karaberov
  • 12,483
  • 10
  • 40
  • 69
  • So you mean if i want to have the oportunity to use markers with the 360 degrees for example, i will need 360 individual drawable ? :S Or could convert the drawable to bitmap, rotate, then convert back to drawable? – Adam Varhegyi Jul 10 '13 at 12:59
  • 1
    @AdamVarhegyi If you want to bypass standard API restrictions - there are only dirty ways:). See my edits about `setIcon` method.It's much better but need an update of API. – Oleksandr Karaberov Jul 10 '13 at 13:02
3

Have you tried marker.rotation(float value)?

take a look at https://developers.google.com/maps/documentation/android/marker#flatten_a_marker

Oleg Novosad
  • 2,070
  • 1
  • 23
  • 27
  • I think this is only applicable to rotations done in XY-plane. Am I right? If yes, then how we can accomplish rotations around x-axis and/or y-axis? Any thoughts? I have recently posted a post [here](http://stackoverflow.com/questions/32554925/android-animate-rotation-of-map-marker-around-x-and-y-axis). Will be glad if you let me know what you think. Thanks! (I'm using Google maps v2 API set) – Kevin Ghaboosi Sep 19 '15 at 20:59