适用于iOS的可调整大小的GMSCircle GoogleMaps SDK

时间:2016-07-27 03:39:12

标签: ios swift google-maps google-maps-sdk-ios gmsmapview

有没有办法调整(缩小和扩展)GMSCircle对象? 我创建了GMSCircle并将其附加到我们的地图中

var cirlce: GMSCircle!

let camera = GMSCameraPosition.cameraWithLatitude(-33.86, longitude: 151.20, zoom: 6)
mapView = GMSMapView.mapWithFrame(CGRectZero, camera: camera)

cirlce = GMSCircle(position: camera.target, radius: 100000)
cirlce.fillColor = UIColor.redColor().colorWithAlphaComponent(0.5)
cirlce.map = mapView

我想让circle回复我的手势来调整大小并获得其圆圈的半径值。例如,它有一个网络版here

那么如何创造呢?任何帮助,将不胜感激。谢谢!

1 个答案:

答案 0 :(得分:3)

 @IBOutlet weak var googleMaps: GMSMapView!
//Slider object to zoom in out the GMSCricle
 @IBOutlet weak var sliderer: UISlider!
 var cirlce: GMSCircle!
 var zoom: Float = 14.0
 var circleSliderZooming: Double = 1000
 var circleCenter = CLLocationCoordinate2D()
 var locationManager = CLLocationManager()


override func viewDidLoad() {
super.viewDidLoad()

locationManager = CLLocationManager()
locationManager.delegate = self
locationManager.requestWhenInUseAuthorization()
locationManager.startUpdatingLocation()
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.startMonitoringSignificantLocationChanges()

self.circleview(redius: 1000)

//Your map initiation code
let camera = GMSCameraPosition.camera(withLatitude: -7.9293122, longitude: 112.5879156, zoom: zoom)
self.googleMaps.camera = camera
self.googleMaps.delegate = self
self.googleMaps?.isMyLocationEnabled = true
self.googleMaps.settings.myLocationButton = true
self.googleMaps.settings.compassButton = true
self.googleMaps.settings.zoomGestures = true
}

func circleview(redius:Double) {
   circleCenter = CLLocationCoordinate2D(latitude: -7.9293122, longitude: 112.5879156)
   cirlce = GMSCircle(position: circleCenter, radius: redius)
   cirlce.fillColor = UIColor(red: 0, green: 0, blue: 0.3, alpha: 0.2)
   cirlce.strokeColor = .blue
   cirlce.strokeWidth = 2
   cirlce.map = googleMaps 
}

 func mapView(_ mapView: GMSMapView, didChange position: GMSCameraPosition) {
  cirlce.position = position.target
 }
 //This is the Slider function to zoom in and out by Slider on View Controller
 @IBAction func cricleZoom(_ sender: Any) {
  cirlce.radius = CLLocationDistance(sliderer.value)   
 }