我正在为ios swift使用这个library“位置选择器”。
它基本上是搜索地图上的各个地方,各种各样的地方。
我可以限制只搜索学校吗?我只需要找学校
我正在使用swift4和最新的xCode
非常感谢你
IBAction函数
@IBAction func pickASchool(_ sender: UIBarButtonItem) {
let locationPicker = LocationPickerViewController()
let longitude :CLLocationDegrees = -122.0312186
let latitude :CLLocationDegrees = 37.33233141
let location = CLLocation(latitude: latitude, longitude: longitude) //changed!!!
print(location)
CLGeocoder().reverseGeocodeLocation(location, completionHandler: {(placemarks, error) -> Void in
print(location)
if error != nil {
print("Reverse geocoder failed with error" + (error?.localizedDescription)!)
return
}
print("no error")
if (placemarks?.count)! > 0 {
print("in pm")
let pm = placemarks![0]
// you can optionally set initial location
let initialLocation = Location(name: "My home", location: location, placemark: pm)
locationPicker.location = initialLocation
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
}
self.navigationController?.pushViewController(locationPicker, animated: true)
print(pm.locality!)
}
else {
print("Problem with the data received from geocoder")
}
})
}
最佳答案
我唯一的解决办法就是选个地方。然后,检查name属性。如果这个名字是由下面的一个词组成的,那就是学校。
-学校
-研究所
-大学
-大学。。。
感谢@DharmeshKheni
关于ios - 如何仅在Swift LocationPicker库中搜索学校,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/48016982/