9

I am a new developer for Android. Tried to rotate MapView in circular motion. But I don't know how to begin.

Do you have a simple code to rotate the MapView?

Macarse
  • 91,829
  • 44
  • 175
  • 230
Ferdinand
  • 1,193
  • 4
  • 23
  • 43

2 Answers2

11

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() :)

Romain Guy
  • 97,993
  • 18
  • 219
  • 200
1

As a general case, you can always created an Affine Transform with the angled rotation you need. In the general case, you do a matrix multiplication of this form:

|x'|   |cosθ  -sinθ   0| |x|
|y'| = |sinθ  cosθ    0|*|y|
|1 |   |0      0      1| |1|

Where (x,y) are your initial coordinates, θ is your angle of rotation, and (x',y') are the resultant transformation.

Scott
  • 16,711
  • 14
  • 75
  • 120
  • Another question regarding how to use Affine Transform in android: http://stackoverflow.com/questions/3534642/how-to-map-javas-affinetransform-to-androids-matrix – Macarse Jul 09 '11 at 19:26