我有这段代码,我想将从 MKLocalSearch 获得的位置保存在一个数组中,以便以后使用它们。你有什么想法我该怎么做?
func searchForBarsAndRestaurants(searchFor: String){
let request = MKLocalSearchRequest()
request.naturalLanguageQuery = typeOfPlace //or whatever you're searching for
request.region = MKCoordinateRegionMakeWithDistance(location.coordinate, 300, 300)
let search = MKLocalSearch(request: request)
search.start { response, error in
guard let response = response
else {
print("There was an error searching for: \(String(describing: request.naturalLanguageQuery)) error: \(String(describing: error))")
return
}
print(response.mapItems.count)
print("There are \(response.mapItems.count)" , searchFor)
for item in response.mapItems {
// You may be able to match the address to what the geoCode gives you
// or present the user with a list of options
print("\(String(describing: item.name))")
var totalDistances: Array<Double> = Array()
let distance = self.location.distance(from: item.placemark.location!)
totalDistances += [distance]
print("distance is " ,distance)
print(totalDistances.count)
}
}
}