How do I set a bearing to my ITS icon - Android

Viewed 17

I have a location on my map and I want that my ITS location (compass_0) icon "looks" to the location that I have on the map. The location in the map (nearestDnemRecord) is like a point of interest for my ITS (compass_0), so I want to rotate it in the direction of my point of interest on the map. You can understand what I want to do from my code

public static float getBearing(double fromLatitude, double fromLongitude, double toLatidude, double toLongitude) {
            Location fromLocation = new Location("");//provider name is unnecessary
            fromLocation.setLatitude(fromLatitude);
            fromLocation.setLongitude(fromLongitude);

            Location toLocation = new Location("");//provider name is unnecessary
            toLocation.setLatitude(toLatidude);
            toLocation.setLongitude(toLongitude);
            Log.i("Bearing", fromLocation.bearingTo(toLocation) + "");
            return fromLocation.bearingTo(toLocation);
        }

public Bitmap getCompassBitmap(float rotationInDegree) {
        Bitmap input = compass_0;
        Matrix matrix = new Matrix();
        matrix.setRotate(rotationInDegree);
        Bitmap output = Bitmap.createBitmap(input,0,0,input.getWidth(),input.getHeight(),matrix,true);
        return output;
    }

public void main() {
float rotation = getBearing(mLastLocation.getLatitude(),mLastLocation.getLongitude(),nearestDnemRecord.getLatitude(), nearestDnemRecord.getLongitude());
roadHazarCompass.setImageBitmap(getCompassBitmap(rotation));
}
 

So my goal is to rotate compass_0 icon in the direction of the nearestDnemRecord that is a location on the map

0 Answers
Related