我试图获得两点之间的路线,以获得两点之间的步行距离。但我总是得到以下错误:
错误:
/SourceCache/ProtocolBuffer/ProtocolBuffer-225/Runtime/PBRequester.m:799 server (https://gsp-ssl.ls.apple.com/directions.arpc) returned error: 400
2015-08-12 16:19:34.354 projectName[2995:597568] RESPONSE: (null)
这是我的代码:
-(void)viewDidLoad{
[super viewDidLoad];
[self.view setBackgroundColor:[UIColor whiteColor]];
MKPlacemark *spot1 = [[MKPlacemark alloc] initWithCoordinate:CLLocationCoordinate2DMake(51.21299581976029, 4.404984000000013) addressDictionary:nil];
MKPlacemark *spot2 = [[MKPlacemark alloc] initWithCoordinate:CLLocationCoordinate2DMake(51.20173651985178, 4.450245532177766) addressDictionary:nil];
MKMapItem * startItem = [[MKMapItem alloc] initWithPlacemark:spot1];
MKMapItem * destinationItem = [[MKMapItem alloc] initWithPlacemark:spot2];
NSLog(@"START: %@",startItem);
NSLog(@"DESTINATION: %@",destinationItem);
MKDirectionsRequest * directionsRequest = [[MKDirectionsRequest alloc] init];
[directionsRequest setSource:startItem];
[directionsRequest setSource:destinationItem];
[directionsRequest setTransportType:MKDirectionsTransportTypeWalking];
MKDirections *direction = [[MKDirections alloc] initWithRequest:directionsRequest];
[direction calculateDirectionsWithCompletionHandler:^(MKDirectionsResponse *response, NSError *error) {
NSLog(@"RESPONSE: %@",response);
}];
}
我测试了不同的互联网连接,以确保这不是问题。 我还按照Apple's Documentation的所有步骤来配置我的应用程序以接受路线请求,但没有任何帮助。
答案 0 :(得分:1)
[directionsRequest setSource:destinationItem];
应为[directionsRequest setDestination:destinationItem];
您正在设置源两次(或者更确切地说,用第二个值覆盖第一个值)。然后你要求没有目的地的路线,当然现在有办法计算,所以你得到一个错误。