Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 253
lufthansa747 Avatar asked Nov 11 '22 04:11

lufthansa747


1 Answers

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.

like image 192
Aniket Bochare Avatar answered Nov 14 '22 21:11

Aniket Bochare