iphone - 查找两个位置之间的角度

标签 iphone ios cllocationmanager angle

我有两个位置的纬度和经度。

我已经找出了这两个位置之间的距离。

CLLocation *locA = [[CLLocation alloc] initWithLatitude:[player.strLatitude floatValue] longitude:[player.strLongitude floatValue]];
CLLocation *locB = [[CLLocation alloc] initWithLatitude:app.lat longitude:app.lag];
CLLocationDistance distance = [locB distanceFromLocation:locA];
NSLog(@"Distance%f",distance);
[locA release]; [locB release];

现在我想找出这两个位置之间的角度。

中心有一个用户位置,我想以适当的角度在该 Cicle 中显示其他用户位置。

感谢您的帮助。

enter image description here

最佳答案

也许这会对你有帮助

- (CGFloat)angleBetweenLinesInRadians:(CGPoint)line1Start 
                         line1End:(CGPoint)line1End 
                       line2Start:(CGPoint)line2Start 
                         line2End:(CGPoint)line2End 
{
CGFloat a = line1End.x - line1Start.x;
CGFloat b = line1End.y - line1Start.y;
CGFloat c = line2End.x - line2Start.x;
CGFloat d = line2End.y - line2Start.y;

CGFloat line1Slope = (line1End.y - line1Start.y) / (line1End.x - line1Start.x);
CGFloat line2Slope = (line2End.y - line2Start.y) / (line2End.x - line2Start.x);

CGFloat degs = acosf(((a*c) + (b*d)) / ((sqrt(a*a + b*b)) * (sqrt(c*c + d*d))));


return (line2Slope > line1Slope) ? degs : -degs;    

}

关于iphone - 查找两个位置之间的角度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15681674/

相关文章:

ios - 使用哪个?委托(delegate)与 keyPathObserver - 具有两个 UIScrollView 的 UIViewController

ios - 有没有更好的方法来处理来自 CLLocationManager 的大量标题数据以呈现在 UI 上?

ios - 如果用户允许该应用程序,则从框架访问用户位置

iPhone模态视图-如何返回父父 Controller

iphone - 魔法记录删除实体问题

iphone - 确认 UIGestureRecognizer?

ios - 如何在 Scenekit 中确定几何表面的方向

ios - 在collectionView中拖放单元格时创建一个新部分?

ios - Swift 3.0 允许权限警报不间断

iphone - 无法同时满足约束