我的位置和目的地之间没有路线

时间:2017-08-03 19:50:42

标签: ios objective-c mapkit

我在这里使用MapWithRoutes代码[MapWithRoutes] [1]

[1]:https://github.com/kadirpekel/MapWithRoutes。它给了我正确的位置和目的地,但无法计算他们之间的路线,我认为      这段代码中的问题:

-(NSArray*) calculateRoutesFrom:(CLLocationCoordinate2D) f to: 
(CLLocationCoordinate2D) t {
NSString* saddr = [NSString stringWithFormat:@"%f,%f", f.latitude, 
f.longitude];
NSString* daddr = [NSString stringWithFormat:@"%f,%f", t.latitude, 
t.longitude];

NSString* apiUrlStr = [NSString 
stringWithFormat:@"http://maps.google.com/maps?
output=dragdir&saddr=%@&daddr=%@", saddr, daddr];
NSURL* apiUrl = [NSURL URLWithString:apiUrlStr];
NSLog(@"api url: %@", apiUrl);
NSString *apiResponse = [NSString stringWithContentsOfURL:apiUrl];
NSString* encodedPoints = [apiResponse stringByMatching:@"points:\\\"
([^\\\"]*)\\\"" capture:1L];

return [self decodePolyLine:[encodedPoints mutableCopy]];
 }

或者可能正在查看路线:

-(NSArray*) calculateRoutesFrom:(CLLocationCoordinate2D) f to: 
(CLLocationCoordinate2D) t {
NSString* saddr = [NSString stringWithFormat:@"%f,%f", f.latitude, 
f.longitude];
NSString* daddr = [NSString stringWithFormat:@"%f,%f", t.latitude, 
t.longitude];

NSString* apiUrlStr = [NSString 
stringWithFormat:@"http://maps.google.com/maps?
output=dragdir&saddr=%@&daddr=%@", saddr, daddr];
NSURL* apiUrl = [NSURL URLWithString:apiUrlStr];
NSLog(@"api url: %@", apiUrl);
NSString *apiResponse = [NSString stringWithContentsOfURL:apiUrl];
NSString* encodedPoints = [apiResponse stringByMatching:@"points:\\\"
([^\\\"]*)\\\"" capture:1L];

return [self decodePolyLine:[encodedPoints mutableCopy]];
}

代码什么错误没有返回路由?

1 个答案:

答案 0 :(得分:2)

根据Mkmapview中的路线绘制折线 检查此answer.