找到2条折线之间的角度

时间:2013-09-04 06:23:09

标签: iphone ios mkmapview mkpolyline

我在MkMapView中的MKPolyLineView上的两组坐标之间绘制MKPolyLines。一条线是从一个点到另一个点的实际路线,而另一条线是两点之间的最短距离。我已成功绘制了两组线。现在我需要在两条线之间找到方向的角度。尽管我付出了努力,但我还是找不到任何有用的东西。需要帮助。

这就是我绘制折线的方法。

self.routeLine = [MKPolyline polylineWithCoordinates:pointsToUse count:[array count]];
self.straightLine = [MKPolyline polylineWithCoordinates:straightLinePoints count:2];

[self.map addOverlay:self.routeLine];
[self.map addOverlay:self.straightLine];

- (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id <MKOverlay>)overlay
{
if(overlay == self.routeLine){
// ylineView *polyLineView = [[MKPolylineView alloc] initWithPolyline:self.polyLine];
polyLineView = [[MKPolylineView alloc] initWithPolyline:self.routeLine];
polyLineView.lineWidth = 2;
polyLineView.strokeColor = [UIColor lightGrayColor];
polyLineView.backgroundColor = [UIColor grayColor];
return polyLineView;
}
else{
    polyLineView = [[MKPolylineView alloc] initWithPolyline:self.straightRouteLine];
    polyLineView.lineWidth = 2;
    polyLineView.strokeColor = [UIColor redColor];
    polyLineView.backgroundColor = [UIColor redColor];
    return polyLineView;
}
}

1 个答案:

答案 0 :(得分:0)

我在Python中编写了一些代码。我可以在以后回家时发布代码,但它看起来像这样:

angle = atan2(y2 - y1, x2 - x1) * 180 / PI;
相关问题