Skip to content Skip to sidebar Skip to footer

How Can I Replace The Compass Image Of Mylocationoverlay?

I want to use my image to replace the Compass image of MyLocationOverlay, how can i implement?

Solution 1:

Subclass MyLocationOverlay, override the method drawCompass(Canvas canvas, float bearing), and draw your own bitmap(s) onto the canvas object:

@OverrideprotectedvoiddrawCompass(Canvas canvas, float bearing) {

    Resourcesres= _context.getResources();
    BitmapmyCompassPointer= BitmapFactory.decodeResource(res, R.drawable.compass_pointer);

    floatrotationAngle= -bearing + 360f;
    Matrixrotation=newMatrix();
    rotation.preRotate(rotationAngle, myCompassPointer.getWidth()/2.0f, myCompassPointer.getHeight()/2.0f);

    canvas.drawBitmap(myCompassPointer, rotation, null);

    // don't call super if you don't want the default compass image://super.drawCompass(canvas, bearing);

}

Solution 2:

I think you can only replace the Marker (the blue, pulsating dot) which displays the location, please see a related StackOverflow question. Hope this helps, even if the issue seems a bit old.

Post a Comment for "How Can I Replace The Compass Image Of Mylocationoverlay?"