【问题标题】:dynamically Change Itemized overlay draw circle using seek bar progress使用搜索栏进度动态更改逐项叠加绘制圆
【发布时间】:2013-01-17 21:32:58
【问题描述】:

我正在使用地图制作一个应用程序。我正在使用逐项叠加在特定点上画圆 它工作得很好。但我想用搜索栏进度值改变那个圆的半径。任何机构都可以指导我吗 提前致谢。

【问题讨论】:

    标签: android google-maps draw itemizedoverlay


    【解决方案1】:

    要在地图上绘制圆圈我们必须使用 itemozied Overlay 但是要使用搜索栏的进度进行更改我们需要执行以下操作,这将与搜索栏一起使用,并且如果您想使用设置缩放级别seek bar 是在下面的代码片段中处理的

    注意:我使用了最小值为 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);
    
    
    
    
        }
    

    【讨论】:

    • 这也适用。您需要做的就是删除以前的 cicle 并添加新的。改变了我的答案。我正在使用相同的技术并且它有效。我正在使用滑块来改变我的圈子。
    • @FahadIshaque 你能解释一下这个“* (1/ FloatMath.cos((float) Math.toRadians(MapController.mylat)))”
    【解决方案2】:

    我介绍一个很好的示例和教程,由 Google 提供,是 Android 官方指南。

    首先,访问this site in the Google Dev guide

    其次,在HERE in Google Dev guide 处获取参考上述指南的示例代码。

    第三,在上面示例代码的src/目录下找到“PolylineDemoActivity.java”。 我想这就是你想知道的。

    你可以使用seekbar进度值改变圆的半径~!

    欲了解更多信息,请与我联系。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多