Iphone 将MKPointAnnotation以特定距离放置在MKDirections上

Iphone 将MKPointAnnotation以特定距离放置在MKDirections上,iphone,objective-c,ios7,mapkit,Iphone,Objective C,Ios7,Mapkit,我使用MKDirections来绘制从点a到点B的路线,并且我希望在距离起点的特定距离处放置一个MKPointAnnotation 例如,我有一个从洛杉矶到纽约绘制的带有MKDirections的MKMap。然后,我想在10英里标记处为用户决定的路线放置一个pin 关于如何在特定距离使用所选路线查找横向/纵向有何想法 谢谢 - (void)showDirections:(MKDirectionsResponse *)response { NSInteger iDistance = 0;

我使用MKDirections来绘制从点a到点B的路线,并且我希望在距离起点的特定距离处放置一个MKPointAnnotation

例如,我有一个从洛杉矶到纽约绘制的带有MKDirections的MKMap。然后,我想在10英里标记处为用户决定的路线放置一个pin

关于如何在特定距离使用所选路线查找横向/纵向有何想法

谢谢

- (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;
            }
         }
    }
}
-(void)showDirections:(MKDirectionsResponse*)响应
{
NSInteger-iDistance=0;
BOOL bPointinStep=否;
自我反应=反应;
用于(MKRoute*响应中的路由_response.routes)
{
NSLog(@“路线距离:%.0f”,路线距离);
responseNumber=responseNumber+1;
[_MapViewAddOverlay:route.polyline level:mkOverlaylevelOverroads];
用于(MKRouteStep*路径中的步骤。步骤)
{
iDistance=iDistance+step.distance;
NSLog(@“iDistance:%.0ld”,(长)iDistance);
NSLog(@“步长距离:%.0f”,步长距离);
NSLog(@“%@”,步骤说明);
如果(i进程

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

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

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

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


我希望它能对您有所帮助。

您是否尝试过任何方法>如果是,请发布您的代码。我没有尝试过任何方法来获取lat/long,但是我能够获取距离发生在哪个MKRouteStep中。有没有办法确定台阶内的特定点。多段线?看起来这需要一些工作:找出台阶内哪两个坐标(a,B)包含10英里位置(P)。getCoordinates:range:方法在这里可能会有所帮助。了解从A到10英里标记还需要行驶多少英里。从A到B查找轴承(SDK中没有方法)。最后,用一个算法找到P的坐标。我担心这就是答案。我暗暗希望SDK中有一些超级秘密的方法来解决这个问题。谢谢你的回答。如果你想要信用卡,请你发一个回复。