Reputation: 33
I'm trying to get details about a place using the Google Places API for iOS. When attempt to call the lookUpPlaceID
function, receiving the following Swift compiler error:
Cannot invoke 'lookUpPlaceID' with an argument list of type '(String, callback: (GMSPlace!, _) -> Void)'
let placeID = "ChIJV4k8_9UodTERU5KXbkYpSYs"
placesClient!.lookUpPlaceID(placeID, callback: { (place: GMSPlace!, error) -> Void in
if error != nil {
println("lookup place id query error: \(error.localizedDescription)")
return
}
if place != nil {
println("Place name \(place.name)")
println("Place address \(place.formattedAddress)")
println("Place placeID \(place.placeID)")
println("Place attributions \(place.attributions)")
} else {
println("No place details for \(placeID)")
}
})
I'm using the example code available in the Google Places API documentation here:
https://developers.google.com/places/ios/place-details#get-place
The placesClient is an object of type GMSPlacesClient. Earlier in the code, I am able to successfully call the placesClient autcompleteQuery function, so I don't think it's a problem with my placesClient.
Any help or suggestions would be greatly appreciated.
Upvotes: 3
Views: 1886
Reputation: 3596
In the callback, you need to replace the type (GMSPlace
) with the variable name that you want to use, which you correctly did for error
.
It should be something like:
let placeID = "ChIJV4k8_9UodTERU5KXbkYpSYs"
placesClient!.lookUpPlaceID(placeID, callback: { (place, error) -> Void in
if error != nil {
println("lookup place id query error: \(error!.localizedDescription)")
return
}
if let p = place {
println("Place name \(p.name)")
println("Place address \(p.formattedAddress)")
println("Place placeID \(p.placeID)")
println("Place attributions \(p.attributions)")
} else {
println("No place details for \(placeID)")
}
})
Also, make sure to unwrap those optional variables (both place and error) before using them, by doing force unwrapping (!), like I did for error
above, or by using if let
, like I did for place
.
Hope this helps.
Upvotes: 5