Closed emadd closed 7 years ago
You mean the place selected by the user from the table that appears with the options? The value
of the row should be that place
Thanks! So it appears to return both the query text (userInput) or the selected place (prediction) . How do you tell the difference between the two?
The value is of type GooglePlace
which is an enum. If the user selected a value from the table view or collection view then the value will be a GooglePlace.prediction
. If the user did not select anything but just left his written text in the row then the value will be a GooglePlace.userInput
Sorry, I'm not making myself clear enough. How exactly do I extract the GMSAutocompletePrediction from the GooglePlace?
let place: GooglePlace = row.value!
switch place {
case .prediction:
print("Location Selected")
// TODO: extract the place
case .userInput:
print("userInput")
// Do nothing
}
The prediction or userInput is an associated value of the GooglePlace
enum
public enum GooglePlace {
case userInput(value: String)
case prediction(prediction: GMSAutocompletePrediction)
}
So you can get it like this:
switch place {
case let GooglePlace.userInput(val):
return val
case let GooglePlace.prediction(pred):
return pred.attributedFullText.string
}
With "let place: GooglePlace = row.value!" i got the following error: Cannot convert value of type 'GooglePlace' to specified type 'GooglePlace'
Could you provide an example of how to get the place that was selected from a table result set?