I want to draw bitmap on draw method in MyPositionOverlay extends Overlay class but 开发者_如何学GoI get this error: The method getResource() is undefined for the type MyPositionOverlay
Where I'm wrong?
Here is code form draw method:
  Bitmap bmp = BitmapFactory.decodeResource(getResource(), R.drawable.icon); 
     canvas.drawBitmap(bmp, screenPts.x, screenPts.y-50, null);
Thanks
The getResources() method is not a member of the Overlay class. getResources() is a member of the Context class. You need to pass a reference of a Context to your Overlay subclass so that it can load the Drawable resource:
Bitmap bmp = BitmapFactory.decodeResource(context.getResources(), R.drawable.icon); 
You also don't want to load a bitmap in your draw method as it is very memory intensive and will slow down your application, you should save a member variable of the bitmap in the constructor of the overlay so that it only gets loaded once.
use
   Bitmap bmp = BitmapFactory.decodeResource(this.getResources(), R.drawable.icon); 
or
Bitmap bmp = BitmapFactory.decodeResource(Context.getResources(), R.drawable.icon); 
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论