Android 使用搜索栏进度动态更改逐项覆盖绘制圆
我正在用地图制作一个应用程序。我正在使用逐项叠加在特定点上绘制圆 它工作得很好。但是我想用seekbar进程值来改变这个圆的半径。有人能给我指点迷津吗Android 使用搜索栏进度动态更改逐项覆盖绘制圆,android,google-maps,draw,itemizedoverlay,Android,Google Maps,Draw,Itemizedoverlay,我正在用地图制作一个应用程序。我正在使用逐项叠加在特定点上绘制圆 它工作得很好。但是我想用seekbar进程值来改变这个圆的半径。有人能给我指点迷津吗 提前谢谢 要在地图上绘制圆,我们必须使用itemozied覆盖,但要随搜索栏的进度进行更改,我们需要执行以下操作,这将与搜索栏一起使用,并且如果您想使用搜索栏设置缩放级别,则在下面的代码段中进行处理 注意:我使用了最小值为0、最大值为9的搜索栏 public void seekBarProgressEvent() {
提前谢谢 要在地图上绘制圆,我们必须使用itemozied覆盖,但要随搜索栏的进度进行更改,我们需要执行以下操作,这将与搜索栏一起使用,并且如果您想使用搜索栏设置缩放级别,则在下面的代码段中进行处理 注意:我使用了最小值为0、最大值为9的搜索栏
public void seekBarProgressEvent()
{
seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
@Override
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
// TODO Auto-generated method stub
mapView.getOverlays().clear();
if(progress==0)
{
zoomLevel=17f;
}
else if(progress==1)
{
zoomLevel=16f;
}
else if(progress==2)
{
zoomLevel=15f;
}
else if(progress==3)
{
zoomLevel=14f;
}
else if(progress==4)
{
zoomLevel=14f;
}
else if(progress==5)
{
zoomLevel=13.50f;
}
else if(progress==6)
{
zoomLevel=13.10f;
}
else if(progress==7)
{
zoomLevel=12.85f;
}
else if(progress==8)
{
zoomLevel=12.10f;
}
else if(progress==9)
{
zoomLevel=11.85f;
}
//intent.putExtra("radius", radius);
//zoomLevel-=seekBar.getProgress();
Log.i("ZoomLevel", ""+zoomLevel);
mapView.getController().setZoom((int)zoomLevel);
Drawable drawable = getApplicationContext().getResources().getDrawable(R.drawable.mapmarker);
// in Itemized overlay i m drawing circle of Defined Radius like 100m 200m 300m etc
itemizedoverlay = new FolloowMapOverlay(drawable, getApplicationContext(),(radius));
MapPoint = new GeoPoint((int)(mylat*1E6), (int)(mylon*1E6));
OverlayItem overlayitem = new OverlayItem(MapPoint, "Current Location", "");
currentLocationOverlay = new CurrentLocationOverlay(drawable, getApplicationContext());
currentLocationOverlay.addOverlay(overlayitem);
mapView.getOverlays().add(itemizedoverlay);
mapView.getOverlays().add(currentLocationOverlay);
mapView.invalidate();
mapController.setCenter(MapPoint);
mapController.animateTo(MapPoint);
}
});
}
下面是我的逐项覆盖类中的Draw Circle方法
private void drawCircleAtPoint(GeoPoint point, Canvas canvas, MapView mapView) {
Projection projection = mapView.getProjection();
Point pt2 = new Point();
projection.toPixels(point, pt2);
// method that is used to conver the radius to pixel that takes input the radius and draw it on the coresponding pixels
float circleRadius = projection.metersToEquatorPixels(radius) * (1/ FloatMath.cos((float) Math.toRadians(MapController.mylat)));
Paint circlePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
Paint rectangle=new Paint(Paint.ANTI_ALIAS_FLAG);
Log.d("Circular Radius", ""+circleRadius+" "+radius);
circlePaint.setColor(0x99000000);
circlePaint.setStyle(Style.STROKE);
canvas.drawCircle((float)pt2.x, (float)pt2.y, circleRadius, circlePaint);
}
我介绍了谷歌提供的一个很好的示例和教程,这是一个Android官方指南 首先是参观 第二,获取上面指南中提到的示例代码 第三,在上面示例代码的src/目录中找到“PolylineDemoActivity.java”。 我想这就是你想知道的 您可以使用seekbar进度值来更改圆的半径~
有关更多信息,请与我联系。这也适用于此。您所需要做的就是删除以前的cicle并添加新的cicle。我改变了答案。我用的是同样的技术,而且很有效。我正在使用滑块更改我的圆。@FahadIshaque您能解释一下“*(1/FloatMath.cos((float)Math.toRadians(MapController.mylat))”吗