I am developing an iOS app with Xcode 6.4, Swift version 1.2.
I am trying to use Google Places API's functionality Current Place in my app, in order to get the list of places close to the user, then display them in a tableView. In order to guess the location, I have created this function that activates every time the text in search bar changes, and populates an array called PossiblePlaces with suggestions that adapt in real time:
func search(searchText: String? = nil){
self.possiblePlaces = []
if searchText != nil {
println("before query")
placesClient?.currentPlaceWithCallback({ (placeLikelihoods:GMSPlaceLikelihoodList?, error:NSError?) -> Void in
if error != nil {
println("error")
}
if error == nil {
println("query ended")
for likelihood in placeLikelihoods!.likelihoods {
println(likelihood)
let place = likelihood.name
let id = likelihood.identifier
println(id)
println(place)
var suggestion = postedPlace(name: place, id: id)
self.possiblePlaces.append(suggestion)
}
self.autocompleteTableView.reloadData()
}
})
}
}
As far as I can tell, the function launches correctly: I get the "before query" message every time the text changes. However, I get neither "error", nor "query ended", seemingly meaning that the query never launches. I don't know why: the API key is correct, I even get a message on my Google Maps SDK version in the console when the GMSPlacesClient is initialized (in the ViewDidLoad), so I assume the integration works.
I appreciate any input!
Thanks