【问题标题】:no route between my location an destination我的位置和目的地之间没有路线
【发布时间】:2017-08-03 19:50:42
【问题描述】:

我正在使用此处的 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]];
}

代码不返回路由有什么问题?

【问题讨论】:

  • 你有什么问题?
  • 地图上没有显示路线的代码有什么问题?
  • 非常糟糕的代码示例。如何在地图中设置折线?您的函数是否返回折线?
  • 是的,它有 decodePolyLine ,请查看 git hub 链接中的完整代码。

标签: ios objective-c mapkit


【解决方案1】:

在 Mkmapview 中根据路线绘制折线 检查这个answer.

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多