【发布时间】:2014-09-20 08:01:43
【问题描述】:
我正在尝试制作一个简单的应用程序,它允许用户获取与特定地址对应的经度和纬度。我想为用户提供一个类似于谷歌地图中的搜索框。具体来说,我想要某种自动完成功能以确保用户输入有效的地址。是否可以创建谷歌地图搜索框的实例?
【问题讨论】:
标签: ios swift google-maps autocomplete
我正在尝试制作一个简单的应用程序,它允许用户获取与特定地址对应的经度和纬度。我想为用户提供一个类似于谷歌地图中的搜索框。具体来说,我想要某种自动完成功能以确保用户输入有效的地址。是否可以创建谷歌地图搜索框的实例?
【问题讨论】:
标签: ios swift google-maps autocomplete
SPGooglePlacesAutocomplete 是围绕 Google Places Autocomplete API 的简单 Objective-c 包装器。
看看这个来自 github 的 API 可能会有所帮助-https://github.com/spoletto/SPGooglePlacesAutocomplete
按链接显示的用法。添加 .h 文件,您可以从函数中访问实现 Google Place 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);
}];
它还有一个可以使用的示例项目。
【讨论】: