SPGooglePlacesAutocomplete
SPGooglePlacesAutocomplete copied to clipboard
Any way to limit to only cities?
Is there any way to limit the place type so it only returns cities / municipalities?
Thanks
Hello,
There is one. First, you need to add a SPGooglePlacesAutocompletePlaceType (SPPlaceTypeCities for example) in SPGooglePlacesAutocompleteUtilities.h
typedef enum {
SPPlaceTypeInvalid = -1,
SPPlaceTypeGeocode = 0,
SPPlaceTypeCities = 1,
SPPlaceTypeEstablishment
} SPGooglePlacesAutocompletePlaceType;
Next, you need to reimplement some of the code. By now, each return of .m functions is based on a ternary. You need to change it, including SPPlaceTypeCities within.
SPGooglePlacesAutocompletePlaceType SPPlaceTypeFromDictionary(NSDictionary *placeDictionary) {
if ([placeDictionary[@"types"] containsObject:@"cities"])
return SPPlaceTypeCities;
return [placeDictionary[@"types"] containsObject:@"establishment"] ? SPPlaceTypeEstablishment : SPPlaceTypeGeocode;
}
and
NSString *SPPlaceTypeStringForPlaceType(SPGooglePlacesAutocompletePlaceType type) {
switch (type) {
case SPPlaceTypeCities:
return @"(cities)";
break;
case SPPlaceTypeGeocode:
return @"geocode";
default:
return @"establishment";
break;
}
}
Finally, set your google searchQuery.types = SPPlaceTypeCities
and voilà!
I hope there will be some upgrade on that since it is a really useful feature.
Have a nice day!