luf*_*747 5 google-maps autocomplete ios swift
我正在尝试制作一个简单的应用程序,它允许用户获取与特定地址相对应的经度和纬度。我想为用户提供一个类似于谷歌地图中的搜索框。具体来说,我想要某种自动完成功能,以确保用户输入有效地址。是否可以创建谷歌地图搜索框的实例?
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)
Run Code Online (Sandbox Code Playgroud)
然后,调用 -fetchPlaces 来 ping Google 的 API 并获取结果。生成的数组将返回 SPGooglePlacesAutocompletePlace 类的对象。
[query fetchPlaces:^(NSArray *places, NSError *error) {
NSLog(@"Places returned %@", places);
}];
Run Code Online (Sandbox Code Playgroud)
它还有一个可以使用的示例项目。