Gmsplace Returns Invalid Coordinate (-180, -180), But Name and Place Id Are Correct

GMSPlace returns invalid coordinate (-180, -180), but name and place ID are correct

I was facing the same issue and went through the Place SDK documentation which says clearly that we should define before hand to the GMSPlaceField of what details do we need exactly and if you had followed the doc completely, it would be resulting only in the name and placeId being populated.
So while instantiating your GMSAutoCompleteViewController define in the following way.

**let fields: GMSPlaceField = GMSPlaceField(rawValue:UInt(GMSPlaceField.name.rawValue) |
UInt(GMSPlaceField.placeID.rawValue) |
UInt(GMSPlaceField.coordinate.rawValue) |
GMSPlaceField.addressComponents.rawValue |
GMSPlaceField.formattedAddress.rawValue)!
autocompleteController.placeFields = fields**

Swift : Using Google Places with iOS and getting -180 as Latitude

I found it.

Where you present GMSAutocompleteViewController, you can add GMSPlaceField field to specify what data you want, like this:

@objc func autocompleteClicked(_ sender: UIButton) {
let autocompleteController = GMSAutocompleteViewController()
autocompleteController.delegate = self

// Specify the place data types to return.
let fields: GMSPlaceField = GMSPlaceField(rawValue:UInt(GMSPlaceField.name.rawValue) |
UInt(GMSPlaceField.placeID.rawValue) |
UInt(GMSPlaceField.coordinate.rawValue) |
GMSPlaceField.addressComponents.rawValue |
GMSPlaceField.formattedAddress.rawValue)!
autocompleteController.placeFields = fields

// Specify a filter.
let filter = GMSAutocompleteFilter()
filter.type = .noFilter
autocompleteController.autocompleteFilter = filter

// Display the autocomplete view controller.
present(autocompleteController, animated: true, completion: nil)
}

I got this function from https://developers.google.com/places/ios-sdk/autocomplete



Related Topics



Leave a reply



Submit