我在这里使用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]];
}
代码什么错误没有返回路由?