Issue
I created a class MiOverlay that extends from Overlay.
And it doesn't recognize the getResources method.. What do I have to do. Here the full code of my class
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Point;
import android.location.Location;
import com.google.android.maps.MapView;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.Overlay;
public class MiOverlay extends Overlay {
GeoPoint point;
public MiOverlay(GeoPoint point)
{
super();
this.point = point;
}
@Override
public boolean draw(Canvas canvas, MapView mapView, boolean shadow, long when){
super.draw(canvas, mapView, shadow);
Point scrnPoint = new Point();
mapView.getProjection().toPixels(this.point, scrnPoint);
Bitmap marker = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
canvas.drawBitmap(marker, scrnPoint.x - marker.getWidth() / 2, scrnPoint.y - marker.getHeight() /2 , null);
return true;
}
Solution
I disagree with Luis Lavieri's answer. Your easiest solution would be to use the MapView's context:
Bitmap marker = BitmapFactory.decodeResource(mapView.getContext().getResources(), R.drawable.ic_launcher);
Easy and no potential memory leaks.
Answered By - Emanuel Moecklin
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.