android - Rotate marker to the device heading at precise location when map is rotating. -
using new version of mapsforge 0.5.1, map rotates fine onsensorchanged event. have added custom gps location marker @ gps point on onlocationchanged event. when map rotates, marker rotated point towards device heading in google maps using following code in marker's draw method.
android.graphics.canvas androidcanvas = androidgraphicfactory.getcanvas(canvas); androidcanvas.save(); float px = (float) canvas.getwidth()/2; float py = (float) canvas.getheight()/2; androidcanvas.rotate(degree, px, py); canvas.drawbitmap(bitmap, left, top); androidcanvas.restore();
however when map dragged, marker's position disorients previous point of gps location.
how calculate px , py value keep marker @ precise point of gps location on map when map rotating , marker pointing device heading.
i know bit old, future researches found solution :
- first extend mapsforge marker , override draw() method
- copy paste content of draw method marker
- then add following in last condition :
replace :
if(canvasrectangle.intersects(bitmaprectangle)) { canvas.drawbitmap(bitmap, left, top); }
with :
if(canvasrectangle.intersects(bitmaprectangle)) { // rotate marker based on bearing example (or whatever angle want) android.graphics.canvas androidcanvas = androidgraphicfactory.getcanvas(canvas); androidcanvas.save(); float px = (right + left) / 2f; float py = (bottom + top) / 2f; androidcanvas.rotate(bearing, px, py); canvas.drawbitmap(bitmap, left, top); androidcanvas.restore(); }
in case "bearing" member variable of class extenting marker, set 2 different locations earlier in code (gps location). can replace angle suits needs.
Comments
Post a Comment