我已经按照本教程 - https://www.youtube.com/watch?v=AdV7bCWuDYg
了尝试在地图上绘制路线,我确实成功发送了原点/目的地的纬度/经度。问题是它生成的URL。
但据我所知,网址应以 | 45.566346,18.667512 之类的结尾。我不知道我做错了什么,因为教程声称它有效,而我认为它可以。
- (void)setDirectionsQuery:(NSDictionary *)query withSelector:(SEL)selector
withDelegate:(id)delegate{
NSArray *waypoints = [query objectForKey:@"waypoints"];
NSLog(@"***waypoints : %@", waypoints);
NSString *origin = [waypoints objectAtIndex:0];
int waypointCount = [waypoints count];
int destinationPos = waypointCount -1;
NSString *destination = [waypoints objectAtIndex:destinationPos];
NSString *sensor = [query objectForKey:@"sensor"];
NSMutableString *url =
[NSMutableString stringWithFormat:@"%@&origin=%@&destination=%@&sensor=%@",
kMDDirectionsURL,origin,destination, sensor];
if(waypointCount>2) {
[url appendString:@"&waypoints=optimize:true"];
int wpCount = waypointCount-2;
for(int i=1;i<wpCount;i++){
[url appendString: @"|"];
[url appendString:[waypoints objectAtIndex:i]];
}
}
url = [[url
stringByAddingPercentEscapesUsingEncoding: NSASCIIStringEncoding]mutableCopy];
_directionsURL = [NSURL URLWithString:url];
NSLog(@"url : %@", url);
[self retrieveDirections:selector withDelegate:delegate];}
经过数小时的研究后,我在Google Directions页面上注意到,所需的网址格式与我使用过的网格格式略有不同,但仍然没有运气。
[NSMutableString stringWithFormat:@“%@ origin =%@&amp; destination =%@&amp; key = [my api key], kMDDirectionsURL,出发地,目的地];
答案 0 :(得分:0)
您的网址应该有效,我将原点更改为旧金山并将目的地更改为Mountain View并且它可以正常工作:
http://maps.googleapis.com/maps/api/directions/json?&origin=san+francisco&destination=mountain+view&sensor=false
谷歌地图可能不知道如何从37.661519,127.061106到37.664185,127.062994