lufthansa747
lufthansa747

Reputation: 2061

How to make Location auto complete text box Swift ios 8

I am trying to make a simple app which allows the user to get the longitude and latitude corresponding to a specific address. I want to provide the user with a search box similar to the one in google maps. Specifically I would like some sort of autocompletion to ensure the user enters a valid address. Is it possible to create an instance of google maps search box?

Upvotes: 5

Views: 2558

Answers (1)

Aniket Bochare
Aniket Bochare

Reputation: 427

SPGooglePlacesAutocomplete is a simple objective-c wrapper around the Google Places Autocomplete API.

Look at this API from github which might be helpful- https://github.com/spoletto/SPGooglePlacesAutocomplete

Usage shown as per link. Adding the .h file you can have access to the functions which implement the Google places API from within the function. You can set parameters like partial address string, radius, language your app uses, your location (lat,long)

#import "SPGooglePlacesAutocompleteQuery.h"

...

SPGooglePlacesAutocompleteQuery *query = [SPGooglePlacesAutocompleteQuery query];
query.input = @"185 berry str";
query.radius = 100.0;
query.language = @"en";
query.types = SPPlaceTypeGeocode; // Only return geocoding (address) results.
query.location = CLLocationCoordinate2DMake(37.76999, -122.44696)

Then, call -fetchPlaces to ping Google's API and fetch results. The resulting array will return objects of the SPGooglePlacesAutocompletePlace class.

[query fetchPlaces:^(NSArray *places, NSError *error) {
    NSLog(@"Places returned %@", places);
}];

It also has a example project which can be used.

Upvotes: 1

Related Questions