I am creating an application which trakcs down users path on a mapview. What I want to achieve when user takes a left turn for instance map should rotate it self in such a way that the head of the mapview should always point to upward direction. I hope that makes sense.
I came across Mr. Romain Guy’s post an he says
I have done this in the past and it
requires to create a custom ViewGroup
that rotates the Canvas in the
dispatchDraw() method. You also need
to increase the size of the MapView
(so that it draws enough pixels when
rotated.) You will also need to rotate
the touch events in
dispatchTouchEvent(). Or if you use
Android 3.0 you can simply call
theMapView.rotate() :
Does anyone came accross some solution similiar to my question ? A working example would be excellent 🙂
Keep in mind that it’s not an ideal approach, because the text on the map is a static image and will rotate along with the map tiles (at some point it will be upside down).
Here’s an example of how to put the
MapViewinto your ownLayoutwidget and rotate it. I’ve done it with the OpenStreetMaps, but it should be quite the same for Google Maps.First create the “rotating”
LayoutwidgetSurround by it your
MapViewin thelayout.xmlNow, every time you receive a geo fix, update the bearing of the rotating layout and it should turn.