0

I'm using Google Map v2. And I want to select some region from map. I want to provide the functionality when user moves his finger on screen and I want to draw a circle to select the region from map. How to do that?

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_free_draw);

    fram_map = (FrameLayout) findViewById(R.id.fram_map);
    fram_map.addView(new DrawView(FreeDrawActivity.this));

    map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map))
            .getMap();
    Marker hamburg = map.addMarker(new MarkerOptions().position(HAMBURG)
            .title("Hamburg"));
    Marker kiel = map.addMarker(new MarkerOptions()
            .position(KIEL)
            .title("Kiel")
            .snippet("Kiel is cool")
            .icon(BitmapDescriptorFactory
                    .fromResource(R.drawable.ic_launcher)));

    map.getUiSettings().setScrollGesturesEnabled(false);

    cameraPosition = getIntent().getExtras().getParcelable("position");
    // Move the camera instantly to hamburg with a zoom of 15.
    map.moveCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));

    // Zoom in, animating the camera.
    // map.animateCamera(CameraUpdateFactory.zoomTo(10), 2000, null);

    val = new ArrayList<LatLng>();
    fram_map.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            float x = event.getX();
            float y = event.getY();

            int x_co = Math.round(x);
            int y_co = Math.round(y);

            projection = map.getProjection();
            Point x_y_points = new Point(x_co, y_co);

            LatLng latLng = map.getProjection().fromScreenLocation(
                    x_y_points);
            latitude = latLng.latitude;

            longitude = latLng.longitude;

            int eventaction = event.getAction();
            switch (eventaction) {
            case MotionEvent.ACTION_DOWN:
                // finger touches the screen
                val.add(new LatLng(latitude, longitude));

            case MotionEvent.ACTION_MOVE:
                // finger moves on the screen
                val.add(new LatLng(latitude, longitude));

            case MotionEvent.ACTION_UP:
                // finger leaves the screen
                Draw_Map();
                break;
            }

            if (Is_MAP_Moveable == true) {
                return true;

            } else {
                return false;
            }
        }
    });
}

public void Draw_Map() {
    PolygonOptions rectOptions = new PolygonOptions();
    rectOptions.addAll(val);
    rectOptions.strokeColor(Color.BLUE);
    rectOptions.strokeWidth(7);
    rectOptions.fillColor(Color.CYAN);
    Polygon polygon = map.addPolygon(rectOptions);
}

this code draw a polygon with finger moves. but I want to draw circle.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Umesh Kumar Saraswat
  • 758
  • 3
  • 10
  • 28

1 Answers1

0

try like this,

 public void Draw_Map(LatLng point) {
      CircleOptions circleOptions = new CircleOptions()
  .center(point)   //set center
  .radius(500)   //set radius in meters
  .fillColor(Color.TRANSPARENT)  //default
  .strokeColor(Color.BLUE)
  .strokeWidth(5);

  Circle myCircle = myMap.addCircle(circleOptions);
    }
Akash Moradiya
  • 3,318
  • 1
  • 14
  • 19