我从这里[MapWithRoutes] [1]使用MapWithRoutes代码
[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]];
}
代码不返回路由怎么了?
最佳答案
根据Mkmapview中的路线绘制折线
检查此answer.
关于ios - 我的位置和目的地之间没有路线,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/45493375/