Draw circle of certain radius on map view in Android

后端 未结 6 801
一向
一向 2020-12-08 11:55

I want to draw a circle on map view. I want the user to input the radius and for that radius I have to show circle on map. After that I have to display markers on some locat

6条回答
  •  清歌不尽
    2020-12-08 12:33

    In the implementation of the ItemizedOverlay, do something like the method drawCircle from the onDraw method

    protected void drawCircle(Canvas canvas, Point curScreenCoords) {
        curScreenCoords = toScreenPoint(curScreenCoords);
        int CIRCLE_RADIUS = 50;
        // Draw inner info window
        canvas.drawCircle((float) curScreenCoords.x, (float) curScreenCoords.y, CIRCLE_RADIUS, getInnerPaint());
        // if needed, draw a border for info window
        canvas.drawCircle(curScreenCoords.x, curScreenCoordsy, CIRCLE_RADIUS, getBorderPaint());
    }
    
    private Paint innerPaint, borderPaint;
    
    public Paint getInnerPaint() {
        if (innerPaint == null) {
            innerPaint = new Paint();
            innerPaint.setARGB(225, 68, 89, 82); // gray
            innerPaint.setAntiAlias(true);
        }
        return innerPaint;
    }
    
    public Paint getBorderPaint() {
        if (borderPaint == null) {
            borderPaint = new Paint();
            borderPaint.setARGB(255, 68, 89, 82);
            borderPaint.setAntiAlias(true);
            borderPaint.setStyle(Style.STROKE);
            borderPaint.setStrokeWidth(2);
        }
        return borderPaint;
    }
    
    @Override
    protected void onDraw(Canvas canvas) {
        Point p = new Point();
        for(OverlayItem item : items) {
            drawCircle(canvas, getProjection().toPixels(item.getPoint(), p));
        }
    }
    

提交回复
热议问题