问题描述
Helllo所有人,在谷歌地图中,我需要显示一个圆圈,用户可以调整它的大小,缩放并拖动它,之后我需要找到圆的半径和中心的经纬度。
对于Tappable GMSCircle集合
googleMapCircle.tappable = true;
为了实现可拖动的圆圈,需要添加Google map的委托方法 didTapOverlay :
- (void)mapView:(GMSMapView *)mapView
didChangeCameraPosition :( GMSCameraPosition *)定位
{
//将GMSCameraPosition设置为googleMapCircle位置
googleMapCircle.position = position.target;
调整GMSCircle在滑块值上的大小更改
在滑块值更改方法中添加以下代码:
<$ p (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];
//为了实现圆圈半径的增加或减少,首先清除地图视图
[_googleMap clear];
//设置要绘制的中心坐标circle
CLLocationCoordinate2D circleCenter = CLLocationCoordinate2DMake(_locationManager.location.coordinate.latitude,_locationManager.location.coordinate.longitude);
//在Google地图上绘制圆圈
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;
}
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 ?
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 changeAdd 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; }
这篇关于在Google地图目标-c中调整大小,拖动和缩放GMSCircle的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!