我正在使用来自此处 [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中根据路线绘制Polyline 检查这个answer.
关于ios - 我的位置和目的地之间没有路线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45493375/