问题
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:
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;
}
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;
}
来源:https://stackoverflow.com/questions/40991640/resize-drag-and-scale-gmscircle-in-google-map-objective-c