android - Rotating the Canvas impacts TouchEvents -


i have map application using in-house map engine on android. i'm working on rotating map view rotates map based on phone's orientation using sensor service. works fine exception of dragging map when phone pointing other north. example, if phone facing west, dragging map still moves map south versus east expected. i'm assuming translating canvas 1 possible solution i'm not sure correct way this.

here code i'm using rotate canvas:

public void dispatchdraw(canvas canvas) {     canvas.save(canvas.matrix_save_flag);     // mheading orientation sensor     canvas.rotate(-mheading, origin[x],origin[y]);       mcanvas.delegate = canvas;     super.dispatchdraw(mcanvas);     canvas.restore(); } 

what best approach make dragging map consistent regardless of phones orientation? sensormanager has "remapcoordinates()" method it's not clear resolve problem.

you can trivially delta x , delta y between 2 consecutive move events. correct these values canvas rotation can use simple trignometry:

void correctpointforrotate(pointf delta, float rotation) {      // angle of movement (0=up, 90=right, 180=down, 270=left)     double = math.atan2(-delta.x,delta.y);      = math.todegrees(a);  // ranges -180 +180     += 180;      // adjust angle amount map rotated around center point     += rotation;     = math.toradians(a);      // calculate new corrected panning deltas     double hyp = math.sqrt(x*x + y*y);     delta.x = (float)(hyp * math.sin(a));     delta.y = -(float)(hyp * math.cos(a)); } 

Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

sql server - python to mssql encoding problem -

windows - Python Service Installation - "Could not find PythonClass entry" -