测试已测试 | ✗ |
语言语言 | SwiftSwift |
许可证 | MIT |
发布最后发布 | 2017年11月 |
SwiftSwift 版本 | 3.0 |
SPM支持 SPM | ✗ |
由 Adrian Apodaca 和 Koldo Ruiz 维护。
LocationPickerViewController
是一个 UIViewController
子类,允许用户通过搜索或选择地图上的点来选择位置。
它旨在像 UIImagePickerController
一样工作。
用户可以通过搜索或长按地图来选择位置。在这两种情况下,您都会收到 CLPlacemark,其中包含位置坐标以及国家、州、城市、街道地址和 POI 名称等信息。
使用 Swift 3,对于 Swift 2/Xcode 7 使用版本 0.6.0
。
github "almassapargali/LocationPicker"
pod 'ByvLocationPicker'
地图 | 搜索 | 选择 |
---|---|---|
![]() |
![]() |
![]() |
在代码中创建一个新的实例(LocationPickerViewController()
)或通过在 Storyboard 中设置 UIViewController
类。
然后提供完成块,当用户关闭视图控制器时会被调用。
let locationPicker = LocationPickerViewController()
// you can optionally set initial location
let location = CLLocation(latitude: 35, longitude: 35)
let initialLocation = Location(name: "My home", location: location)
locationPicker.location = initialLocation
// button placed on right bottom corner
locationPicker.showCurrentLocationButton = true // default: true
// default: navigation bar's `barTintColor` or `.whiteColor()`
locationPicker.currentLocationButtonBackground = .blueColor()
// ignored if initial location is given, shows that location instead
locationPicker.showCurrentLocationInitially = true // default: true
locationPicker.mapType = .Standard // default: .Hybrid
// for searching, see `MKLocalSearchRequest`'s `region` property
locationPicker.useCurrentLocationAsHint = true // default: false
locationPicker.searchBarPlaceholder = "Search places" // default: "Search or enter an address"
locationPicker.searchHistoryLabel = "Previously searched" // default: "Search History"
// optional region distance to be used for creation region when user selects place from search results
locationPicker.resultRegionDistance = 500 // default: 600
locationPicker.completion = { location in
// do some awesome stuff with location
}
navigationController?.pushViewController(locationPicker, animated: true)
LocationPicker 在 MIT 许可证下可用。有关更多信息,请参阅 LICENSE 文件。