测试已测试 | ✗ |
语言语言 | SwiftSwift |
许可证 | MIT |
发布日期最后发布 | 2015年6月 |
SPM支持 SPM | ✗ |
由 Howard Wilson 维护。
简单方便的适用于 iOS 设备的 Google Places API 自动补全地址输入视图。
已经有一些这样的解决方案。GooglePlacesAutocomplete 与它们不同,因为它是完全用 Swift 编写的,旨在提供最简单的方法输入验证过的自动补全地址。
没有尝试集成 MapKit,因为将 Google Places 显示在非 Google 地图中违反了他们的服务条款。
![]() |
![]() |
内嵌框架需要至少 iOS 8 的最低部署目标。
如果您的项目目标为 iOS 7,则必须直接在项目中包含 GooglePlacesAutocomplete 的源文件。有关说明,请参阅“手动安装”部分。
只需将 GooglePlacesAutocomplete.swift
和 GooglePlacesAutocomplete.xib
复制到项目中。
注意:别忘了将 PoweredByGoogle.png 图片添加到您的 xcassets 中。
import GooglePlacesAutocomplete // Not required when including source files directly in project
let gpaViewController = GooglePlacesAutocomplete(
apiKey: "[YOUR GOOGLE PLACES API KEY]",
placeType: .Address
)
gpaViewController.placeDelegate = self // Conforms to GooglePlacesAutocompleteDelegate
presentViewController(gpaViewController, animated: true, completion: nil)
GooglePlacesAutocompleteDelegate
支持以下方法:
placesFound(places: [Place])
:每当 Google Places API 被调用时,都会执行该方法placeSelected(place: Place)
:当选中新地点时执行该方法placeViewClosed()
:当视图关闭时执行该方法以下是一个完整的示例:完整示例。
根据 Google 的文档:“通过初始化一个 地点详情 请求,您可以请求有关特定场所或兴趣点的更多信息。地点详情请求返回了有关指定地点的更全面的信息,如完整的地址、电话号码、用户评分和评论。”
place.getDetails { details in
println(details.name) // Convenience accessor for name
println(details.latitude) // Convenience accessor for latitude
println(details.longitude) // Convenience accessor for longitude
println(details.raw) // Complete JSON data (see below)
}
/*
[
status: OK,
result: {
"address_components" = (
{
"long_name" = Paris;
"short_name" = Paris;
types = (
locality,
political
);
},
...
);
geometry = {
location = {
lat = "48.856614";
lng = "2.3522219";
};
...
*/
有关完整响应的详细信息,请参阅文档。
可以轻松更改 UINavigationController 的外观,例如:
gpaViewController.navigationBar.barStyle = UIBarStyle.Black
gpaViewController.navigationBar.translucent = false
gpaViewController.navigationBar.barTintColor = UIColor(red: 0.11, green: 0.27, blue: 0.53, alpha: 1.0)
gpaViewController.navigationBar.tintColor = UIColor.whiteColor()
gpaViewController.navigationBar.titleTextAttributes = [NSFontAttributeName: UIFont(name: "Zapfino", size: 16.0)!]
![]() |
另外,为了更改标题栏的内容:
gpaViewController.navigationItem.title = "Enter City"
gpaViewController.navigationItem.leftBarButtonItem = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.Cancel, target: gpaViewController, action: "close")
git checkout -b my-new-feature
)git commit -am '添加一些功能'
)git push origin my-new-feature
)