开发者

Find if device is pointing in the right heading / direction?

I would like to find the distance to a location and which direction the device is heading in relation to that location. I've got the distance working but cant work out how to find the which way the location.

_theLocation = [开发者_JAVA技巧[CLLocation alloc]initWithLatitude:-41.561004 longitude:173.849030];

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
    CLLocationDistance meters = [newLocation distanceFromLocation:_theLocation] * 0.000621371192;
}

- (void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading
{
    NSString *str = [NSString stringWithFormat:@"Heading = %.f", newHeading.trueHeading];  
}  

Is it possible to find the heading to _theLocation from our location?


Can't you simply capture the device's location at two instances & figure out the direction wrt the location?

Not a complete solution, but assuming that the device only moves along the line joining the device & the location, you can use – distanceFromLocation:. If you capture the distance from the location at two instances & see if the latter value is less than the former, you can deduce that the device has moved closer to the location.

In fact, from your question, it appears that you want to determine whether the device has moved closer to the location or not (and not the exact direction, say N or NE). If that's the case, then this should work.

HTH,

Akshay

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜