我有一个允许用户在文本字段中输入地址的应用程序。我想关联一个tableView,其中填充了他们正在寻找的地址的自动完成的猜测(例如,Uber的方式)。到目前为止,我已经使用MapKit构建了我的应用-是否可以通过MapKit来实现此目的,或者可以通过Google Maps SDK来实现?
最佳答案
SPGooglePlacesAutocomplete是围绕Google Places Autocomplete API的简单Objective-C包装。
从github看这个API可能会有帮助-https://github.com/spoletto/SPGooglePlacesAutocomplete
用法按链接显示。添加.h文件,您可以从该函数内访问实现Google Places API的函数。您可以设置参数,例如部分地址字符串,半径,您的应用使用的语言,您的位置(经纬度)
#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)
然后,调用-fetchPlaces来ping Google的API并获取结果。结果数组将返回SPGooglePlacesAutocompletePlace类的对象。
[query fetchPlaces:^(NSArray *places, NSError *error) {
NSLog(@"Places returned %@", places);
}];
它还有一个可以使用的示例项目。
关于ios - iOS8:自动完成地址搜索的最佳方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26665892/