【发布时间】:2013-11-06 20:17:15
【问题描述】:
我正在使用 MKDirections 绘制从 A 点到 B 点的路线,并且我希望将 MKPointAnnotation 放置在距起点的特定距离处。
例如,我有一个 MKMap,其中包含从 LA 到 NY 的 MKDirections。然后,我想在用户决定采取的路线的 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;
}
}
}
}
这很有效,因为我能够确定应该放置哪个步骤,但我的问题是如何确定步骤中的位置。
【问题讨论】:
-
您尝试过什么吗> 如果有,请发布您的代码。
-
我没有尝试任何关于获取纬度/经度的方法,但是我能够获得距离发生在哪个 MKRouteStep 中。有没有办法确定 step.polyline 中的特定点?
-
看起来这需要一些工作:找出步骤中的哪两个坐标 (A,B) 包含 10 英里位置 (P)。 getCoordinates:range: 方法在这里可能会有所帮助。找出从 A 到 10 英里标记还需要多少英里。找到从 A 到 B 的方位(SDK 中没有方法)。最后,使用算法like this找到P的坐标。
-
我担心这会是答案。我暗暗希望SDK中有一些超级秘密的方法。感谢你的回答。如果您想要信用,请您发布作为答案。
标签: iphone objective-c ios7 mapkit