1
votes

I've followed this tutorial - https://www.youtube.com/watch?v=AdV7bCWuDYg

Trying to draw route on map and I do successfully send latitude/longitude of origin/destination. The problem is its generated URL.

I keep getting this http://maps.googleapis.com/maps/api/directions/json?&origin=37.661519,127.061106&destination=37.664185,127.062994&sensor=false

But as far as I know, the URL should end with |45.566346,18.667512 something like that. I don't know what I'm doing wrong because the tutorial claims it works and its by Google I think.

- (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];}

After hours of research I've noticed on Google Directions page that the required URL format is a little different from the one I've been using but still no luck.

[NSMutableString stringWithFormat:@"%@origin=%@&destination=%@&key=[my api key], kMDDirectionsURL,origin,destination];

1

1 Answers

0
votes

Your url should work, I changed the origin to San Francisco and destination to Mountain View and it works:
http://maps.googleapis.com/maps/api/directions/json?&origin=san+francisco&destination=mountain+view&sensor=false

It is possible that Google Maps does not know how to get from 37.661519,127.061106 to 37.664185,127.062994

enter image description here