Resize, drag and scale GMSCircle in Google map obj

2019-06-07 20:09发布

Helllo Everyone, In google map i need to show a circle and user can resize it, scale it and drag it also and after that i need to find radius of the circle and center latitude and longitude. How can i achieve this ?

1条回答
beautiful°
2楼-- · 2019-06-07 20:56

For Tappable GMSCircle set

googleMapCircle.tappable = true;

And to achieve draggable circle need to add the delegate method of Google map didTapOverlay :

- (void)mapView: (GMSMapView*)mapView
didChangeCameraPosition: (GMSCameraPosition*)position
{
   //set GMSCameraPosition to  googleMapCircle position
    googleMapCircle.position=position.target;

}

enter image description here

For resize GMSCircle on slider value change Add below code in slider value change method :

- (IBAction)sliderValueChnage:(id)sender {

  _slider = (UISlider*)sender;
    NSLog(@"slider value = %f", _slider.value);

    int radius=(int)_slider.value;
     _lblRadius.text=[NSString stringWithFormat:@"%d m",radius];


//For achieve circle radius increase or decrease properly ,first clear map view 
    [_googleMap clear];

//Set centre coordinate  where you want to draw circle
CLLocationCoordinate2D circleCenter = CLLocationCoordinate2DMake(_locationManager.location.coordinate.latitude, _locationManager.location.coordinate.longitude);

// Draw circle on google map
    GMSCircle *googleMapCircle = [GMSCircle circleWithPosition:circleCenter
                                             radius:_slider.value];
    googleMapCircle.fillColor = [[UIColor purpleColor] colorWithAlphaComponent:.4f];
    googleMapCircle.strokeColor = [UIColor purpleColor];
    googleMapCircle.strokeWidth = 5;
    googleMapCircle.tappable=YES;
    googleMapCircle.map = _googleMap;


}

enter image description here

enter image description here

查看更多
登录 后发表回答