I am developing an android application in I have two GeoPoints in Google map.One GeoPoint is fix and other GeoPoint is my current location. On my current location I am placing an arrow point in direction of fix GeoPoint,as my current location changes so the arrow will change its direction.It works fine but in most cases it showing wrong direction.
Here is my code.
Paint paint = new Paint();
GeoPoint gp1;
GeoPoint gp2;
Point point1,point2;
Projection projection = mapView.getProjection();
projection.toPixels(gp1, point1);
projection.toPixels(gp2, point2);
Bitmap bmp = BitmapFactory.decodeResource(getResources(),R.drawable.arrow);
double dlon = gp2.getLongitudeE6() - gp1.getLongitudeE6();
double dlat = gp2.getLatitudeE6() - gp1.getLatitudeE6();
double a = (Math.sin(dlat / 2) * Math.sin(dlat / 2)) + Math.cos(gp1.getLatitudeE6()) * Math.cos(gp2.getLatitudeE6()) * (Math.sin(dlon / 2) * Math.sin(dlon / 2));
double angle = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
Matrix matrix = new Matrix();
matrix.postTranslate(-25, -25);
matrix.postRotate(convertToRadians(angle));
matrix.postTranslate(point1.x, point1.y);
paint.setAntiAlias(true);
paint.setFilterBitmap(true);
canvas.drawBitmap(bmp, matrix, paint);
Waiting for your help and thanks in advance.
Altaf