班上的相关部分是:
- (void)viewDidLoad
{
[super viewDidLoad];
[self requestFiles];
fileData = [[NSMutableData alloc] init];
self.mapView = [[SKMapView alloc]initWithFrame:CGRectMake(0.0f, 0.0f, CGRectGetWidth(self.view.frame), CGRectGetHeight(self.view.frame))];
self.mapView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[SKRoutingService sharedInstance].mapView = self.mapView;
[SKRoutingService sharedInstance].routingDelegate = self;
}
-(void) generateContent{
self.container.contentSize = CGSizeMake(320, numberOfRoutes*65);
for (int i = 0; i<numberOfRoutes; i++) {
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(0,i*50, 320, 55);
[button addTarget:self action:@selector(displayRoute:) forControlEvents:UIControlEventTouchUpInside];
[button setTag:i+1];
[self.container addSubview:button];
}
}
-(void)displayRouteFile:(NSString *) fname{
if (downloadComplete) {
for (UIView *item in self.container.subviews) {
[item removeFromSuperview];
}
[self generateContent];
downloadComplete = NO;
self.mapView.frame = CGRectMake(0,(activeButtonNumber+1)*50+10, 320, 200);
self.container.contentSize = CGSizeMake(320, self.container.contentSize.height+210);
for (UIView *item in self.container.subviews) {
if ([item isKindOfClass:[UIButton class]]) {
UIButton *buttonToMove = (UIButton *) item;
if (buttonToMove.tag>activeButtonNumber+1) {
[buttonToMove setCenter:CGPointMake(item.center.x, item.center.y+220)];
}
}
}
[[SKRoutingService sharedInstance]clearCurrentRoutes];
[[SKRoutingService sharedInstance] clearAllRoutesFromCache];
[[SKRoutingService sharedInstance] clearRouteAlternatives];
[[SKRoutingService sharedInstance] startRouteFromGPXFile:fname];
[self.container addSubview:self.mapView];
}
}
-(IBAction)displayRoute:(UIButton *)sender{
UIButton *button = (UIButton *)sender;
[button setBackgroundImage:activeButtonBackground forState:UIControlStateNormal];
int route = button.tag-1;
activeButtonNumber = route;
receiveFile = YES;
//download route
...
fileData = [[NSMutableData alloc] init];
}
- (void)routingService:(SKRoutingService *)routingService didFinishRouteCalculationWithInfo:(SKRouteInformation*)routeInformation{
NSLog(@"Route is calculated with id: %u", routeInformation.routeID);
[routingService zoomToRouteWithInsets:UIEdgeInsetsZero];
// zoom to current route
^^^THIS PART DOES NOT WORK^^^
}
- (void)routingServiceDidFailRouteCalculation:(SKRoutingService *)routingService{
NSLog(@"Route calculation failed.");
}
-(void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
[[SKRoutingService sharedInstance]clearCurrentRoutes];
activeButtonNumber = 0;
}
我有一个名为TestThis的Activity,我多次打开它(每次我提供一个导致GPX文件的不同文件路径)。第一次打开Activity时整个过程运行正常 - 无论我提供什么文件路径,它都会显示路径,然后放大它。如果我返回并选择另一个文件路径来创建活动,则会显示新路线,但地图会缩放到其他位置。
这就是事情发生的顺序:
公共类TestThis扩展Activity实现SKRouteListener,SKMapSurfaceListener {
private static SKMapSurfaceView mapView;
String path;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.prazen);
Bundle bundle = getIntent().getExtras();
path = bundle.getString("filepath");
RelativeLayout theArea = (RelativeLayout) findViewById(R.id.placeHere);
SKMapViewHolder myMapHolder = new SKMapViewHolder(TestThis.this);
mapView = myMapHolder.getMapSurfaceView();
mapView.setMapSurfaceListener(this);
mapView.getMapSettings().setCurrentPositionShown(false);
theArea.addView(myMapHolder);
SKRouteManager.getInstance().setRouteListener(TestThis.this);
}
@Override
public void onRouteCalculationCompleted(final int statusMessage, final int routeDistance, final int routeEta, final boolean thisRouteIsComplete, final int id) {
//SKRouteManager.getInstance().zoomToRoute((float)1.2, (float)1.2, 110, 8, 8, 8);
if(SKRouteManager.getInstance().setCurrentRouteByUniqueId(id)){
System.out.println("Current route selected!");
}
}
@Override
public void onAllRoutesCompleted() {
System.out.println("On all routes compl");
SKRouteManager.getInstance().zoomToRoute((float)1.2, (float)1.2, 110, 8, 8, 8);
//SKRouteManager.getInstance().zoomMapToCurrentRoute();
}
@Override
public void onSurfaceCreated() {
// TODO Auto-generated method stub
SKRouteManager.getInstance().clearCurrentRoute();
SKRouteManager.getInstance().setRouteFromGPXFile(path, SKRouteSettings.SKROUTE_CAR_SHORTEST, false, false, false);
}
}
答案 0 :(得分:1)
<强> IOS 强> 该错误在客户端。
问题在于,当计算路线时,使用地图视图的前一帧,这就是路线不居中的原因。移动
之前的[self.container addSubview:self.mapView];
[[SKRoutingService sharedInstance] clearCurrentRoutes];
[[SKRoutingService sharedInstance] clearAllRoutesFromCache];
[[SKRoutingService sharedInstance] clearRouteAlternatives];
[[SKRoutingService sharedInstance] startRouteFromGPXFile:fname];
应该解决问题。
<强>机器人:强> 在创建活动后立即调用zoomToRoute()时,可能会出现缩放不正确的问题。作为该问题的解决方法,可以遵循与v2.2开源演示相同的方法:避免活动重新创建并从与显示地图的活动相同的活动中选择GPX轨道 - 请参阅中的“轨道”选项演示菜单。
原始错误/原因将在未来的更新中解决。