I'm trying to convert the simple GMSPlacePicker example to Swift
but the Picker appears but then disappears immediately as soon as the transition from Right to left completes.
// ViewController.swift
import UIKit
import CoreLocation
import GoogleMaps
class ViewController: UIViewController {
@IBAction func buttonPlacesPicker_TouchUpInside(sender: AnyObject) {
//-----------------------------------------------------------------------------------
var southWestSydney : CLLocationCoordinate2D = CLLocationCoordinate2DMake(-33.8659, 151.1953)
var northEastSydney : CLLocationCoordinate2D = CLLocationCoordinate2DMake(-33.8645, 151.1969)
var sydneyBounds : GMSCoordinateBounds = GMSCoordinateBounds(coordinate: southWestSydney, coordinate:northEastSydney)
//var config : GMSPlacePickerConfig = GMSPlacePickerConfig(viewport:sydneyBounds)
var config : GMSPlacePickerConfig = GMSPlacePickerConfig(viewport:nil)
//---------------------------------------------------------------------
var placePicker : GMSPlacePicker = GMSPlacePicker(config: config)
//typealias GMSPlaceResultCallback = (GMSPlace?, NSError?) -> Void
var error: NSError? = nil
var gmsPlace: GMSPlace? = nil
placePicker.pickPlaceWithCallback(){
(gmsPlace, error) -> Void in
if let error = error{
println("error:\(error)")
}else{
if let gmsPlace = gmsPlace{
if let formattedAddress = gmsPlace.formattedAddress{
println("formattedAddress:\r\(formattedAddress)")
}else{
println("gmsPlace.formattedAddress is nil")
}
}else{
println("gmsPlace is nil")
}
println("info")
}
}
}
}
My app has asked for Location sucessfully
I have a bridging header to Google Maps.
I didnt use cocoa pods to install the framework
but I've used the framework in Obj-C before
so just dragged the GoogleMaps.framework to project and the internal resources bundle
I added all the following from previous tutorials and linker errors:
When I run it I can see sydney in the pickers maps.
It transitions from right side fo the screen to the left.
When it reaches the left it disappears
I added Reveal app and I cant see the picker view offline.
My GMS services api key is correct as its one I used in obj-c app to show Places Picker.
Bundle id is correct.
My Swift knowledge is "I think I know it. I probably don't"
any ideas?
You should retain the reference to your GMSPlacePicker. Make it a property instead of local variable.