I want to sort my TableView by distance, but I have mixed up:( Please help me if You can, I would appreciate it, really :(
I have an array with 100 objects.
var malls: [Mall] = [
Mall(name: "Европейский", type: "торговый центр", image: "europe.jpg", time: "с 10.00 до 22.00",
timeWeek: "с 10.00 до 23.00", city: "Москва", location: "Киевская",
adress: "г. Москва, Киевского вокзала площадь, д.2", cinemaName:"formulakino.png",
productName: "perekrestok.png", numShop: "309", website: "http://europe-tc.ru", schemeWeb:"http://www.europe-tc.ru/shops/", longitude:37.566, latitude:55.745),
Mall(name: "Золотой Вавилон Ростокино", type: "торговый центр", image: "vavilon.jpg", time: "с 10.00 до 22.00",
timeWeek: "с 10.00 до 22.00", city: "Москва", location: "Проспект Мира",
adress: "г. Москва, Проспект Мира, д. 211", cinemaName: "Люксор",
productName: "okay.png", numShop: "280", website: "http://zolotoy-vavilon.ru/rostokino", schemeWeb:"http://www.zolotoy-vavilon.ru/rostokino/map", longitude:37.663, latitude:55.846), ]
and so on.. sorry for Cyrillic
and after override func tableView I have this
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation])
{
let currentLocation = locations[0]
if (currentLocation.horizontalAccuracy > 0 ) {
locationManager.stopUpdatingLocation()
let coords = CLLocation(latitude: currentLocation.coordinate.latitude, longitude: currentLocation.coordinate.longitude)
**let mallLocate = CLLocation(latitude: mall.latitude, longitude: mall.longitude)**
let distanceInMeters = mallLocate.distance(from: coords)
print (distanceInMeters)
}
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as! EateriesTableViewCell
let mall = mallToDisplayAt(indexPath: indexPath)
cell.thumbnailImageView.image = UIImage(named: mall.image)
cell.thumbnailImageView.clipsToBounds = true
cell.nameLabel.text = mall.name
cell.locationLabel.text = mall.location
cell.typeLabel.text = mall.time
return cell
}
I have problem in this row
let mallLocate = CLLocation(latitude: mall.latitude, longitude: mall.longitude)
Use of unresolved identifier 'mall'
How can I fix it? and how to do sort by directions? Thank you so much.
See Question&Answers more detail:
os