SPGooglePlacesAutocomplete icon indicating copy to clipboard operation
SPGooglePlacesAutocomplete copied to clipboard

Any way to limit to only cities?

Open simonbromberg opened this issue 11 years ago • 1 comments

Is there any way to limit the place type so it only returns cities / municipalities?

Thanks

simonbromberg avatar Sep 16 '13 04:09 simonbromberg

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!

LouisBorlee avatar Jul 07 '14 16:07 LouisBorlee