如何只搜索Swift LocationPicker库中的学校

时间:2017-12-29 03:14:47

标签: ios swift location swift4

我正在为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")
        }
    })



}

1 个答案:

答案 0 :(得分:0)

我得到的唯一解决方案是获得所选地点。然后,检查名称属性。如果名称由以下单词之一组成,那么它就是学校。 - 学校 - 研究所 - 大学 - 大学...

感谢@DharmeshKheni