I have a strange issue when trying to initialize a GMSCircle class from the Google Maps SDK.
I have this function in my MapViewController which contains a GMSMapView:
func createCircleOnMap(map: GMSMapView, circleCenter: CLLocationCoordinate2D, circleRadius: Double) {
print("TEST 1")
let addCircle = GMSCircle()
print("TEST 2")
addCircle.position = circleCenter
addCircle.radius = circleRadius
addCircle.map = map
}
If I call this function from viewDidLoad() or the mapView delegate "didTapAtCoordinate", I can add a circle to the map without a problem.
However, if I call the function from a completion handler (in my case after returning information from AWS Lambda via the AWS SDK), I never get past the GMSCircle initialization.
This is my Lambda function:
func getMapData() {
let json: NSDictionary = ["test" : "TEST"]
let lambdaInvoker = AWSLambdaInvoker.defaultLambdaInvoker()
lambdaInvoker.invokeFunction("MyLambdaFunction", JSONObject: json, completionHandler: { (response, err) -> Void in
if (err != nil) {
print("Error: \(err)")
} else if (response != nil) {
// PARSE THE JSON HERE
self.createCircleOnMap(<#T##map: GMSMapView##GMSMapView#>, circleCenter: <#T##CLLocationCoordinate2D#>, circleRadius: <#T##Double#>)
}
})
}
The json parses fine (I checked those values), and when I pass it to createCircleOnMap, I get:
print("TEST 1")
in the console, but nothing else. It just stops without an error.
I also get the same result if I move the "addCircle" code to inside the Lambda function completion handler. My test print log "TEST 1" returns, but the script just stops without an error.
I also tried the initializer:
let addCircle = GMSCircle(position: circleCenter, radius: circleRadius)
with the same result.
I'm not even sure how to debug this issue. I've checked all the values, including sending hard-coded values to the function from inside the Lambda completion handler, and it still doesn't work. Maybe I just don't understand enough about Swift.
Any ideas?