android - How can I draw an Arrow showing the driving direction in MapView? -


i use google maps component mapview in android application. can use gps location show location dot. show arrow instead, points out driving direction (bearing). think can use bearing value angle of arrow.

how can that?

assuming you've got location obtain bearing doing:

float mybearing = location.getbearing(); 

to implement overlay you'll using itemizedoverlay , overlayitem. you'll need subclass overlayitem add functionality rotate drawable. like:

public bitmapdrawable rotatedrawable(float angle) {   bitmap arrowbitmap = bitmapfactory.decoderesource(context.getresources(),                                                      r.drawable.map_pin);   // create blank bitmap of equal size   bitmap canvasbitmap = arrowbitmap.copy(bitmap.config.argb_8888, true);   canvasbitmap.erasecolor(0x00000000);    // create canvas   canvas canvas = new canvas(canvasbitmap);    // create rotation matrix   matrix rotatematrix = new matrix();   rotatematrix.setrotate(angle, canvas.getwidth()/2, canvas.getheight()/2);    // draw bitmap onto canvas using matrix   canvas.drawbitmap(arrowbitmap, rotatematrix, null);    return new bitmapdrawable(canvasbitmap);  } 

then remains done apply new drawable overlayitem. done using setmarker() method.


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -