package com.example;import android.content.Context;import android.graphics.Bitmap;import android.graphics.BitmapFactory;import android.graphics.Canvas;import android.graphics.Matrix;import android.graphics.Point;import android.location.Location;import com.google.android.maps.GeoPoint;import com.google.android.maps.MapView;import com.google.android.maps.MyLocationOverlay;publicclassMyCustomLocationOverlayextendsMyLocationOverlay{privateContext mContext;privatefloat mOrientation;publicMyCustomLocationOverlay(Context context,MapView mapView){super(context, mapView);
mContext = context;}@Overrideprotectedvoid drawMyLocation(Canvas canvas,MapView mapView,Location lastFix,GeoPoint myLocation,long when){// translate the GeoPoint to screen pixelsPoint screenPts = mapView.getProjection().toPixels(myLocation,null);// create a rotated copy of the markerBitmap arrowBitmap =BitmapFactory.decodeResource( mContext.getResources(), R.drawable.arrow_green);Matrix matrix =newMatrix();
matrix.postRotate(mOrientation);Bitmap rotatedBmp =Bitmap.createBitmap(
arrowBitmap,0,0,
arrowBitmap.getWidth(),
arrowBitmap.getHeight(),
matrix,true);// add the rotated marker to the canvas
canvas.drawBitmap(
rotatedBmp,
screenPts.x -(rotatedBmp.getWidth()/2),
screenPts.y -(rotatedBmp.getHeight()/2),null);}publicvoid setOrientation(float newOrientation){
mOrientation = newOrientation;}}
made a few changes to the previuos code in order to get it to work properly because the arrow was pointing to the wrong direction and rotating in the opposite direction.