Sonic Master
Sonic Master

Reputation: 1248

Resizable GMSCircle GoogleMaps SDK for iOS

is there any way to resize (shrink and expand) an GMSCircle object? I created GMSCircle and attach it into our maps

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

I want to make circle respond my gesture to resize and get radius value of its circle. For example, there is a web version of it here.

So how to create that? Any help would be appreciated. Thank you!

Upvotes: 3

Views: 1989

Answers (1)

user8002418
user8002418

Reputation:

 @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)   
 }

Upvotes: 4

Related Questions