GooglePlacesSearchController
一个简单的 Google Places API 自动完成地址搜索控制器(iOS设备的UISearchController
子类)。
GooglePlacesSearchController 是 100% Swift 4,是基于 GooglePlacesAutocomplete 的分支。
由于在非 Google 地图上显示 Google Places 违反他们的服务条款,没有尝试集成 MapKit。
屏幕截图
![]() |
![]() |
要求
iOS 8.0+ Xcode 8.0+ / Swift 4.0
安装
GooglePlacesSearchController 通过 CocoaPods 提供。要安装它,只需将以下行添加到您的 Podfile 中
pod 'GooglePlacesSearchController'
用法
要运行示例项目,先克隆仓库,然后在 Example 目录中运行 pod install
。
要在您的代码中集成 GooglePlacesSearchController
,最简单的方法是
let controller = GooglePlacesSearchController(delegate: self,
apiKey: GoogleMapsAPIServerKey,
placeType: .address
// Optional: coordinate: CLLocationCoordinate2D(latitude: 55.751244, longitude: 37.618423),
// Optional: radius: 10,
// Optional: strictBounds: true,
// Optional: searchBarPlaceholder: "Start typing..."
)
然后添加控制器搜索栏 controller.searchBar
到您视图。
要获取选中的地点,使用 viewController(didAutocompleteWith:)
代理方法
extension ViewController: GooglePlacesAutocompleteViewControllerDelegate {
func viewController(didAutocompleteWith place: PlaceDetails) {
print(place.description)
placesSearchController.isActive = false
}
}
作者
Dmitry Shmidt,在众多 贡献者 的帮助下。
许可证
GooglePlacesSearchController
遵循 MIT 许可证。有关更多信息,请参阅 LICENSE 文件。