androidgoogle-mapsdrawitemizedoverlay

dynamically Change Itemized overlay draw circle using seek bar progress


i m maikng an app using Maps. I m drawing circle on a specific point using itemized overlay and it works pretty fine. But i want to change the radius of that circle with the seekbar progress value. Can any body guide me to this Thanks in advance.


Solution

  • To Draw the Circle with on map We have to use itemozied Overlay But to change it with the Progress of Seek Bar We need to do the Following thing that will work with Seek Bar and also if you want to set the zoom level using seek bar It is handled in the following code Snippet

    Note: I have used seek bar with min value of 0 and max value of 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);
                }
            });
    
        }
    

    The following is my Draw Circle method in my itemized overlay class

     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);
    
    
    
    
        }