我使用MKDirectionsRequest在两点之间找到一个MKRoute.
响应将使用以下代码显示在MKMapView上:
响应将使用以下代码显示在MKMapView上:
- MKDirections *directions = [[MKDirections alloc] initWithRequest:request];
- [directions calculateDirectionsWithCompletionHandler:^(MKDirectionsResponse *response,NSError *error)
- {
- if (error)
- {
- NSLog(@"Error : %@",error);
- }
- else
- {
- [_mapView removeOverlays:_mapView.overlays];
- for (MKRoute *route in response.routes)
- {
- [_mapView insertOverlay:route.polyline atIndex:0 level:MKOverlayLevelAboveRoads];
- }
- }
- }];
我的问题是,如果用户正在移动,如果有正确的方法更新MKRoute.我正在使用Atm
- - (void)mapView:(MKMapView *)aMapView didUpdateUserLocation:(MKUserLocation *)aUserLocation
识别移动,在这种方法我删除MKRoute覆盖,并计算和添加新的用户位置新.
我想知道是否有一种方法计算路线只有一次,并以编程方式更新覆盖?
编辑:
我发现这个https://developer.apple.com/library/ios/documentation/MapKit/Reference/MKRouteStep_class/Reference/Reference.html#//apple_ref/occ/cl/MKRouteStep在苹果开发文档.
我想我必须做一些类似的事情
- for (MKRoute *route in response.routes)
- {
- for (MKRouteStep *step in route.steps)
- {
- [_mapView insertOverlay:step.polyline atIndex:0 level:MKOverlayLevelAboveRoads];
- }
- }
但是如何识别实际用户位置背后的哪些步骤?
编辑:另一个选项可能是使用触发事件的定时器(删除旧的叠加层并添加新的叠加层).你怎么看?
- [NSTimer scheduledTimerWithTimeInterval:15 target:self selector:@selector(addRouteOverlay) userInfo:nil repeats:YES];