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

标签 ios objective-c mapkit

我正在使用来自此处 [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/

相关文章:

iOS UIView 子类 - 从类方法中显示/删除(如 UIAlertView)

iphone - UISearchBar 中的清除按钮

objective-c - Objective-C c block 中的代码未按预期执行

ios - MKLocalSearch 提供的结果与原生 Apple map 应用程序中的搜索结果不同

iOS 8 Xcode 6 : App consistently crashes when using top/bottom layout guide for top/bottom constraints

iphone - 向 iOS 开发者帐户添加更多设备

xcode - 如何在 swift 2 (xcode) 中使用 mapkit 放大某个位置

ios - 如何使用MapKit在Swift 3中更改图钉颜色

ios - 没有图像或内容获取的 UITableView 断断续续滚动

iphone - iOS 6 facebook sdk 3.1.1登录错误