私の現在の場所から別の場所への私の総距離を表示したいと私はAnnotation
のサブタイトルの距離のショーをしたい。 は、ここに私のコードですが、それは動作しません:現在の場所から別の場所への注釈の距離を表示
func shopDeal() {
var inKm = ""
let locationsq =
[["title": "Shop Deal","subtitle": "\(inKm) km", "latitude": 31.352792, "longitude": 74.253201],
["title": "Shop Deal", "subtitle": "\(inKm) km", "latitude": 31.403563, "longitude": 74.258200]]
// Span
for location in locationsq {
let annotation = MKPointAnnotation()
annotation.title = location["title"] as? String
annotation.subtitle = location["subtitle"] as? String
annotation.coordinate = CLLocationCoordinate2D(latitude: location["latitude"] as! Double, longitude: location["longitude"] as! Double)
mapView.addAnnotation(annotation)
func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
let myCurrentLoc = locations[locations.count - 1]
let coor1 = CLLocation(latitude: annotation.coordinate.latitude, longitude: annotation.coordinate.longitude)
let coor2 = CLLocation (latitude: myCurrentLoc.coordinate.latitude, longitude: myCurrentLoc.coordinate.longitude)
let distanceInMeters:CLLocationDistance = coor1.distanceFromLocation(coor2)
inKm = String(format: "%.2f", distanceInMeters/1000)
print("\(inKm) km")
}
}
mapView.delegate = self
}
すべてのヘルプは高く評価されています。事前のおかげで地図上の2点(LAT and LONG
)との間に
距離を2か所(つまり、LATとLONG)に計算しますか? –
はい....しかし、基本的に私は距離が注釈の副題に表示されたい... – Kamboh