我正在尝试获取两点之间的路线,以获取两点之间的步行距离。但是我总是最终得到以下错误:
错误:
/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);
}];
}
我使用不同的Internet连接进行了测试,以确保这不是问题。
我还按照Apple's Documentation的所有步骤配置了我的应用程序以接受路线请求,但没有任何帮助。
最佳答案
[directionsRequest setSource:destinationItem];
应该是[directionsRequest setDestination:destinationItem];
您将源设置两次(或者用第二个值覆盖第一个值)。然后,您正在请求没有目的地的路线,当然现在有了一种方法可以计算得出错误。
关于ios - 为什么我无法收到MKDirections回复,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/31968236/