0
に現在の場所からユーザーが移動した距離を計算する方法 がどのように私は総ポリライン距離&は時間は私がUImapkit &コアの場所を使用していますSWIFT 3.0
この私のコード
func locationManager(_ manager: CLLocationManager!, didUpdateToLocation newLocation: CLLocation!, fromLocation oldLocation: CLLocation!) {
if let oldLocationNew = oldLocation as CLLocation?{
let oldCoordinates = oldLocationNew.coordinate
let newCoordinates = newLocation.coordinate
var area = [oldCoordinates, newCoordinates]
print(area)
let polyline = MKPolyline(coordinates: &area, count: area.count)
mkMapView.add(polyline)
}
//calculation for location selection for pointing annoation
if (previousLocation as CLLocation?) != nil{
if previousLocation.distance(from: newLocation) > 10 {
addAnnotationsOnMap(newLocation)
previousLocation = newLocation
}
}else{
//case if previous location doesn't exists
addAnnotationsOnMap(newLocation)
previousLocation = newLocation
}
}