マップ ビューとテーブル ビューを使用してビュー ミックスを作成します。ユーザーの場所からの距離でセルを並べ替えることができればと思います。distanceFromLoaction メソッドを使用しようとしましたが、CLLocationCoordinate にメンバーの distanceFromLocaiton がないことが示されています。別の方法はありますかそれまたはそれを修正しますか?
これは私の配列構造です
import UIKit
import MapKit
class tripSpot: NSObject, MKAnnotation{
var title: String?
var coordinate: CLLocationCoordinate2D
var regionRadius: Double
var location: String?
var type: String?
init(title:String , coordinate: CLLocationCoordinate2D , regionRadius: Double, location: String, type: String ){
self.title = title
self.coordinate = coordinate
self.regionRadius = regionRadius
self.location = location
self.type = type
}
}
と私のテーブルビューコード
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("MapCell") as! mapTableViewCell
self.tripspot.sort({ $0.coordinate.distanceFromLoaction(self.coordinate) < $1.coordinate.distanceInKilometersTo(self.coordinate)})
if searchController.active{
cell.title.text = searchResults[indexPath.row].title
cell.location.text = searchResults[indexPath.row].location
return cell
}else{
cell.title.text = tripspot[indexPath.row].title
cell.location.text = tripspot[indexPath.row].location
return cell
}
アドバイスをありがとう。