How can I replace the Compass image of MyLocationOverlay?

不羁的心 提交于 2019-12-13 03:20:06

问题


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


回答1:


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

@Override
protected void drawCompass(Canvas canvas, float bearing) {

    Resources res = _context.getResources();
    Bitmap myCompassPointer = BitmapFactory.decodeResource(res, R.drawable.compass_pointer);

    float rotationAngle = -bearing + 360f;
    Matrix rotation = new Matrix();
    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);

}



回答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.



来源:https://stackoverflow.com/questions/3553699/how-can-i-replace-the-compass-image-of-mylocationoverlay

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!