本文介紹了在Android的地圖視圖上繪制一定半徑的圓的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我想在地圖視圖上畫一個圓圈.我希望用戶輸入半徑,對于該半徑,我必須在地圖上顯示圓圈.之后,我必須在該圓圈的某些位置顯示標記.
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 locations on that circle.
我知道如何在地圖視圖上顯示標記.
I know how to display markers on on map view.
如何在地圖視圖上繪制圓圈并在該圓圈邊界上顯示標記.
How can I draw circle on map view and to show markers on that circle boundary.
推薦答案
在ItemizedOverlay
的實現中,做類似onDraw中的
方法drawCircle
方法
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));
}
}
這篇關于在Android的地圖視圖上繪制一定半徑的圓的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!