我需要在我使用 Android 中的 Canvas 创建的雷达圆圈图像上显示以下两点(A 和 B)。这两个点具有纬度和经度值。假设 A 点有这些值——
Latitude: 37.33774833333334
Longitude: -121.88670166666667
B点有这些价值观——
Latitude: 37.336453
Longitude: -121.884985
我需要通过从圆的中心点进行某种计算来在画布上显示上述两个点,如下图所示。下面是在 Android 中创建雷达圈的代码,如下所示 -
public class CircleCanvas extends View{
Context context;
int[] imageNames=new int[6];
public CircleCanvas(Context mContext,int mUser,int mfirstDis,int msecondDis,int mthirdDis,int mfourDis,int bgMap) {
super(mContext);
context = mContext;
imageNames[0]=mUser;
imageNames[1]=mfirstDis;
imageNames[2]=msecondDis;
imageNames[3]=mthirdDis;
imageNames[4]=mfourDis;
imageNames[5]=bgMap;
}
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
Paint p = new Paint();
p.setColor(Color.BLACK); //BLACK
p.setStyle(Style.STROKE);
//canvas.drawColor(Color.BLACK); //WHITE
WindowManager mWinMgr = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
@SuppressWarnings("deprecation")
int displayWidth = mWinMgr.getDefaultDisplay().getWidth();
@SuppressWarnings("deprecation")
int displayHeight = mWinMgr.getDefaultDisplay().getHeight();
canvas.drawBitmap(BitmapFactory.decodeResource(getResources(),imageNames[5]), 0, 0, null);
int totalCircle=4;
int radius=40;
int centerimagesize=13;
for (int i = 1; i <= totalCircle; i ++) {
canvas.drawCircle(displayWidth/2,displayHeight/4, i*radius, p);
canvas.drawBitmap(BitmapFactory.decodeResource(getResources(),imageNames[i]), ((displayWidth/2)+(i*radius)),(displayHeight/4), null);
}
canvas.drawLine((displayWidth/2-(totalCircle*radius)), (displayHeight/4), (displayWidth/2+(totalCircle*radius)), (displayHeight/4), p);
canvas.drawLine((displayWidth/2), (displayHeight/4-(totalCircle*radius)), (displayWidth/2), (displayHeight/totalCircle+(4*radius)), p);
canvas.drawBitmap(BitmapFactory.decodeResource(getResources(),imageNames[0]), ((displayWidth/2)-(centerimagesize/2)),((displayHeight/4)-(centerimagesize/2)), null);
invalidate();
}
}
这是上面代码中画布的图像-
我正在通过该onCreate
方法传递我当前在 Canvas 上显示的所有图像
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
FrameLayout main = (FrameLayout) findViewById(R.id.main_view);
CircleCanvas circleCanvas=new CircleCanvas(this,R.drawable.current_user,R.drawable.tenm,R.drawable.twentym,R.drawable.thirtym,R.drawable.fourtym,R.drawable.bg_map);
main.addView(circleCanvas);
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
locationManager.requestLocationUpdates(
LocationManager.GPS_PROVIDER,
MINIMUM_TIME_BETWEEN_UPDATES,
MINIMUM_DISTANCE_CHANGE_FOR_UPDATES,
new MyLocationListener()
);
}
而且我不确定,如何通过从我使用 Canvas 创建的圆的中心点进行计算来在该雷达圆图像上显示两个点(A 和 B)。是否需要进行一些角度计算?A and B
我在 Android 项目的可绘制文件夹中有两个点的单独图像