How To Draw A Circle Around Marker on Google Map in Android

Hi Developer in these Android article we are implementing  google Map accuracy circle around marker. So in these Android blog we are learn How To Draw A Circle Around Marker on Google Map in Android.

First of you can Start you Android studio and make a project and Select a Google map Activity. To draw circle around a pin using Google MAps API v2

Secondly create a google map key for developer console and show your google map and if you have already make these you can just follow these code.

Step : 1 Create a Activity with Select Map Activity. 

In you Map activity you can Add a circle method for drawing a circle on marker. and user google map CircleOption for Drow circle.

CircleOptions circleOptions = new CircleOptions();

Used These method to draw a circle Around the marker and Pass the latLong on these method.

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(100);
    // 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
    mMap.addCircle(circleOptions);

}

Map Activity Full source code.

public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {

    private GoogleMap mMap;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_maps);
        // Obtain the SupportMapFragment and get notified when the map is ready to be used.
        SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
                .findFragmentById(R.id.map);
        mapFragment.getMapAsync(this);
    }

    /**
     * Manipulates the map once available.
     * This callback is triggered when the map is ready to be used.
     * This is where we can add markers or lines, add listeners or move the camera. In this case,
     * we just add a marker near Sydney, Australia.
     * If Google Play services is not installed on the device, the user will be prompted to install
     * it inside the SupportMapFragment. This method will only be triggered once the user has
     * installed Google Play services and returned to the app.
     */
    @Override
    public void onMapReady(GoogleMap googleMap) {
        mMap = googleMap;

        // Add a marker in Sydney and move the camera
        LatLng sydney = new LatLng(-34, 151);
        mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));
        mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
        float zoomLevel = 16.0f; //This goes up to 21
        mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(sydney, zoomLevel));
//        Circle circle = mMap.addCircle(new CircleOptions()
//                .center(new LatLng(-34, 151))
//                .radius(10000)
//                .strokeColor(Color.RED)
//                .fillColor(Color.rgb(135,206,235)));

        drawCircle(new LatLng(-34, 151));
    }

    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(100);
        // 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
        mMap.addCircle(circleOptions);

    }
}
Facebooktwitterredditpinterestlinkedinmail
Recommended
Hii Hello Friend  in these AdSense article i am sharing…