> 
> I am trying to derive a DR fix from an initialized CLLocation.
> 
> Like this. (Playground)
> 
> let fixTime = NSDate(timeInterval: (1.00 * 60.00 * 60.00  * -1.00), 
> sinceDate: NSDate()) // one hour ago
> let fixLocation = CLLocation(coordinate: 
> CLLocationCoordinate2DMake(boatLocation.coordinate.latitude, 
> boatLocation.coordinate.longitude), altitude: 0.00, horizontalAccuracy: 0.00, 
> verticalAccuracy: 0.00,course: heading, speed: knots * 0.51444445,  
> timestamp: fixTime)  // location one hour ago
> 
> 
> I am sure there must be something like…..
> 
> 

For those ever needing this, here is what I came up with. (Heavy credit to SO 
for drLat, drLong and conversation  formulae)


let knotsToMeters =  1852.00
let earthRadius = 6372797.6

func degrees2radians(coordinate:CLLocationDegrees) -> Double {
    
    return (M_PI * coordinate ) / 180.00
}

func radians2degrees(coordinate:CLLocationDegrees) -> Double {
    
    return (180.00 * coordinate ) / M_PI
}


func deadReckonedLocationFrom(fix: CLLocationCoordinate2D, 
bearing:CLLocationDirection, knots:CLLocationSpeed, 
timeSinceReport:NSTimeInterval) -> CLLocationCoordinate2D {
    
    
    let rBearing = degrees2radians(bearing)
    let rFixLat = degrees2radians(fix.latitude)
    let rFixLong = degrees2radians(fix.longitude)
    let rDistance = (knots * timeSinceReport * knotsToMeters) / earthRadius
    
    let drLat =  asin(sin(rFixLat) * cos(rDistance) + cos(rFixLat) * 
sin(rDistance) * cos(rBearing))
    let drLong = rFixLong + atan2(sin(rBearing) * sin(rDistance) * 
cos(rFixLat), cos(rDistance) - sin(rFixLat) * sin(drLat))
    return CLLocationCoordinate2D(latitude: radians2degrees(drLat), longitude: 
radians2degrees(drLong))
}


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to