How to draw circle around a pin using Google MAps API v2

后端 未结 5 1012
刺人心
刺人心 2021-01-31 20:31

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 an

5条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-31 21:31

    Using this method you can select any marker & it will create the circle object for particular marker. you can dynamically change radius of the circle by passing the marker object & radius value to the createCircle() method.

     private GoogleMap mMap;
        /*Create circle objects*/
        Circle currentCircle;
         /**
         * create circle when user want to set region
         * @param currentMarker this is user selected marker
         * @param radius pass radius value to circle object
         */
        private void createCircle(Marker currentMarker ,Double radius){
    
    
              //check circle is exist or not 
                   //if exist remove
                   if(currentCircle!=null){
                     currentCircle.remove();
                     }
            currentCircle=mMap.addCircle(new CircleOptions().center(currentMarker.getPosition()).radius(radius)
                .strokeColor(Color.parseColor("#FF007A93"))
                .fillColor(Color.parseColor("#40007A93"))
                .strokeWidth(2));
            float zoomLevel = getZoomLevel(radius);
            mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(currentMarker.getPosition(), zoomLevel));
        }
    

提交回复
热议问题