-1
テーブルビューのセルにUILabel
があります。これは、2つの座標間の距離を常に表示する必要があります。私は2つの座標(緯度と経度)を持っています。今度は、2つの座標の間の距離を表示するのに成功しましたが、テーブルビューを常に更新することなく、人が動くにつれて私はいつもUILabel
を更新できますか?ここでMiles awayテーブルビューセル
は私のコードです:
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath, object: PFObject?) -> PFTableViewCell? {
let cell = tableView.dequeueReusableCell(withIdentifier: "Cells", for: indexPath as IndexPath) as! MyCell
cell.object = object
let currentLocation = CLLocation()
locManager.distanceFilter = 50
if(CLLocationManager.authorizationStatus() == CLAuthorizationStatus.authorizedWhenInUse ||
CLLocationManager.authorizationStatus() == CLAuthorizationStatus.authorizedAlways){
let coordinate₀ = CLLocation(latitude: CLLocationDegrees(-41)!, longitude: CLLocationDegrees(52.3)!)
let coordinate₁ = CLLocation(latitude: currentLocation.coordinate.longitude, longitude: currentLocation.coordinate.latitude)
let distanceInMeters = coordinate₀.distance(from: coordinate₁)
if(distanceInMeters <= 1609)
{
cell.Distance.text = "\(Float(round(distanceInMeters * 3.28084)).cleanValue) ft"
}
else
{
cell.Distance.text = "\(Float(round(distanceInMeters/1609)).cleanValue) mi"
}
}
}
現在の位置を変更してビューを再読み込みすると、距離は変わりません。どうすればいいですか – john
間違っている可能性のあることがいくつかあります。計算コードにブレークポイントを設定します。関数が呼び出され、新しい計算が実際に正しいことを確認します。 –