Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android how to draw a circle on google map

Tags:

android

I am using the new API(Google Map API V2) for my android application, i have done creating the map and adding markers to it, now my task is to manually create a circle around any of the marker and also i want to provide a functionality to the user that he can increase the radius of that circle accordingly, for this i have given a bar, when user increases that bar the radius of circle will increase and vice versa.

If anybody knows how to do this using Google Map API V2 then please help,

like image 967
Sinku Paliwal Avatar asked Jul 09 '15 11:07

Sinku Paliwal


People also ask

Is there a way to draw a radius on Google Maps?

By default, Google Maps doesn't have any tools to draw & display a radius, so you'll have to use an external tool like the FreeMapTools's radius tool or KML4Earth and create your own map.


1 Answers

try this code

protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_tag_map);

     // Drawing circle on the map
           drawCircle(new LatLng(Latitude, Longitude));
    }

        private void drawCircle(LatLng point){

                // Instantiating CircleOptions to draw a circle around the marker
                CircleOptions circleOptions = new CircleOptions();

                // Specifying the center of the circle
                circleOptions.center(point);

                // Radius of the circle
                circleOptions.radius(20);

                // Border color of the circle
                circleOptions.strokeColor(Color.BLACK);

                // Fill color of the circle
                circleOptions.fillColor(0x30ff0000);

                // Border width of the circle
                circleOptions.strokeWidth(2);

                // Adding the circle to the GoogleMap
                googleMap.addCircle(circleOptions);

            }
like image 114
Finava Vipul Avatar answered Sep 30 '22 01:09

Finava Vipul