- (CLLocationDistance)distanceFromLocation:(const CLLocation *)location;
There is no document about this behavior and no definition about -1.
(Maybe it means invalid distance. ex. CLLocationInvalidDistance = -1 in internal)
CLLocation *location = [[CLLocation alloc] initWithLatitude:37.785834 longitude:-122.406417];
CLLocation *nilLocation = nil;
CLLocationDistance distance;
// distance from nil to location
distance = [location distanceFromLocation:nilLocation];
NSLog(@"distance %f", distance);
// -1.000000
// message send to nil object, results is nil
distance = [nilLocation distanceFromLocation:location];
NSLog(@"distance %f", distance);
// -0.000000
CLLocation の distanceFromLocation: メソッドの引数に nil を渡すと-1が返ってくる。
この挙動はドキュメントには載っていなくて、-1 が何を意味するかも定義されてない。
定義は無いけどたぶん CLLocationInvalidDistance = -1 とか内部的にはなってるんじゃないかな。
No comments:
Post a Comment