开发者

Unable to draw text onto map as overlay

开发者 https://www.devze.com 2023-02-14 06:33 出处:网络
I\'m trying to add text labels next to my overlay images. So far the only way I can see to do this would be to use the draw method and draw the text as overlay. I did this, but somehow it isn\'t showi

I'm trying to add text labels next to my overlay images. So far the only way I can see to do this would be to use the draw method and draw the text as overlay. I did this, but somehow it isn't showing me the drawn text. My code looks like:

 SitesOverlay that extends ItemizedOverlay<OverlayItem>
    public void draw(Canvas canvas, MapView mapView,boolean shadow) {  
    int i;  
    Paint paint=new Paint();  
    paint.setStrokeWidth(1);  
    paint.setARGB(255, 255, 255, 255);  
    paint.setStyle(Paint.Style.STROKE);  
    super.draw(canvas, mapView, shadow);  
    boundCenterBottom(station);  
    canvas.drawText("hullo",28632877,77219722, paint);  
    }  

My constructor in the SitesOverlay class just adds the images to many different GeoPoints. Now, in my OnCreate I have this piece of code:

 map.getOverlays().add(new SitesOverlay(station));

This is adding the list of images in my constructor - SitesOverlay(station) as overlays.

My question is that since I have added my text in the Draw method of the SitesOverlay class and not in this constructor, is this why the text is not being drawn on the map? If so how do I add the text to the map?

Do the things drawn in the draw() method automatically get added as an overlay? Coz i think thats what is causing the pr开发者_开发百科oblem here... Any other way I can add text labels next to my overlay images?

Plz help...


try this..

MyLocationOverlay myTouchOverlay = new MyLocationOverlay ();
List<Overlay> list1 = myMapView.getOverlays();
list1.add(myTouchOverlay);



class MyLocationOverlay extends com.google.android.maps.Overlay {


@Override
    public boolean onTap(GeoPoint p, MapView    mapView)  {
    }

    @Override
    public boolean draw(Canvas canvas, MapView mapView, boolean shadow,
            long when) {

        super.draw(canvas, mapView, shadow);

        Paint paint = new Paint();
        // Converts lat/lng-Point to OUR coordinates on the screen.
        Point myScreenCoords = new Point();

        mapView.getProjection().toPixels(point, myScreenCoords);
        paint.setStrokeWidth(1);
        paint.setARGB(255, 255, 255, 255);
        paint.setStyle(Paint.Style.STROKE);

        paint.setTextSize(20);
        paint.setColor(Color.RED);
        paint.setStrokeWidth(2);


         canvas.drawText("Here I am...", myScreenCoords.x-10,myScreenCoords.y-48, paint);
        return true;
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号