Skip to content

Any way to limit to only cities? #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
simonbromberg opened this issue Sep 16, 2013 · 1 comment
Open

Any way to limit to only cities? #8

simonbromberg opened this issue Sep 16, 2013 · 1 comment

Comments

@simonbromberg
Copy link

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

Thanks

@LouisBorlee
Copy link

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants