1

我正在使用 MKDirections 绘制从 A 点到 B 点的路线,并且我希望将 MKPointAnnotation 放在距起点的特定距离处。

例如,我有一个从 LA 到 NY 绘制 MKDirections 的 MKMap。然后,我想在用户决定采取的路线的 10 英里标记处放置一个大头针。

关于如何在特定距离使用所选路线找到纬度/经度的任何想法?

谢谢。

- (void)showDirections:(MKDirectionsResponse *)response
{
    NSInteger iDistance = 0;
    BOOL bPointinStep = NO;
    self.response = response;
    for (MKRoute *route in _response.routes)
    {
        NSLog(@"route.distance: %.0f", route.distance);
        responseNumber = responseNumber + 1;
        [_mapView addOverlay:route.polyline level:MKOverlayLevelAboveRoads];
        for (MKRouteStep *step in route.steps)
        {

            iDistance = iDistance + step.distance;

            NSLog(@"iDistance: %.0ld", (long)iDistance);
            NSLog(@"step.distance: %.0f", step.distance);
            NSLog(@"%@", step.instructions);
            if (iProgress < iDistance && !bPointinStep) {
                NSLog(@"pin point is on this step");
                bPointinStep = YES;
            }
         }
    }
}

这是可行的,因为我能够确定应该放置哪个步骤,但我的问题是如何确定步骤中的位置。

4

1 回答 1

0

我将解释我解决类似问题的方法。

您可以使用属性 step.polyline.coordinate。它为您提供路线每一步的终点的纬度和经度。当您的变量 iDistance 超过 10 英里时,此步骤的终点(或上一步的终点)将给出您正在寻找的近似坐标。无论如何,您将拥有包含“10 英里”距离的路段。

要获得更准确的坐标,您可以在该段的端点和前一段的端点之间执行一些简单的三角运算,以计算距离并放置 MKPointAnnotation 。

我希望它对你有帮助。

于 2014-03-19T12:11:35.853 回答