Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8341139
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T05:22:57+00:00 2026-06-09T05:22:57+00:00

I am using the Google Directions iOS API. I am getting the data using

  • 0

I am using the Google Directions iOS API. I am getting the data using JSON instead of XML. But I am using AFNetworking to simplify this for me. AFNetworking is available at github. Right now, I am able to display an overlay route from one location to another on an MKMapView. Here is my code:

// AFNETWORKING ==========================================================

        AFHTTPClient *_httpClient = [AFHTTPClient clientWithBaseURL:[NSURL URLWithString:@"http://maps.googleapis.com/"]];

    [_httpClient registerHTTPOperationClass: [AFJSONRequestOperation class]];

    [_httpClient setDefaultHeader:@"Accept" value:@"application/json"];

    NSMutableDictionary *parameters = [[NSMutableDictionary alloc] init];

    [parameters setObject:[NSString stringWithFormat:@"%f,%f", location.coordinate.latitude, location.coordinate.longitude] forKey:@"origin"];

    [parameters setObject:[NSString stringWithFormat:@"%f,%f", location2.coordinate.latitude, location2.coordinate.longitude] forKey:@"destination"];

    [parameters setObject:@"false" forKey:@"sensor"];

    [parameters setObject:@"driving" forKey:@"mode"];

    [parameters setObject:@"metric" forKey: @"units"];

    NSMutableURLRequest *request = [_httpClient requestWithMethod:@"GET" path: @"maps/api/directions/json" parameters:parameters];

    request.cachePolicy = NSURLRequestReloadIgnoringLocalCacheData;

    AFHTTPRequestOperation *operation = [_httpClient HTTPRequestOperationWithRequest:request success:^(AFHTTPRequestOperation *operation, id responseObject) {

        NSInteger statusCode = operation.response.statusCode;

        if (statusCode == 200) {

            [self parseResponse:responseObject];

        } else {

        }

    } failure:^(AFHTTPRequestOperation *operation, NSError *error) { }];

    [_httpClient enqueueHTTPRequestOperation:operation];

// ROUTE SETUP AND RESPONSE RECIEVED METHOD ==========================================================


- (void)parseResponse:(NSDictionary *)response {

NSArray *routes = [response objectForKey:@"routes"];

NSDictionary *routePath = [routes lastObject];

if (routePath) {

    NSString *overviewPolyline = [[routePath objectForKey: @"overview_polyline"] objectForKey:@"points"];

    NSLog(@"Status: %@", [response objectForKey: @"status"]);

    NSLog(@"Legs: %@", [routePath objectForKey: @"legs[]"]);

    _path = [self decodePolyLine:overviewPolyline];

    NSInteger numberOfSteps = _path.count;

    CLLocationCoordinate2D coordinates[numberOfSteps];
    for (NSInteger index = 0; index < numberOfSteps; index++) {
        CLLocation *location = [_path objectAtIndex:index];
        CLLocationCoordinate2D coordinate = location.coordinate;

        coordinates[index] = coordinate;
    }

    polyLine = [MKPolyline polylineWithCoordinates:coordinates count:numberOfSteps];
    [self.mapView addOverlay:polyLine];
}

}

This is the main code to get the route functioning. And it works well! But now what I want to do is get direction list and complete duration and summary. So I took a deep look at Google Directions API Documentation and it tells me to use its different dictionaries and arrays and objects. But I have had no luck. I get a status of OK. When I log the count of the routes array, its only one object. Then the MOST important, legs[] array is NULL.

    NSLog(@"Legs is: %@", [routePath objectForKey: @"legs[]"]);

Output:

Legs is (null)

Legs[] includes everything important like the direction list and duration. Summary is not NULL, it gives the name of one of the streets that the route bypasses. I dont know how that is a summary. Might be because there is only one object in the routes array. waypoint_order and warnings[] are NULL too. bounds and of course overview_polyline are valid, thats how I got the route working.

So whats the problem here? Why are so many of the objects Google Directions API provides NULL when I need them?

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T05:22:59+00:00Added an answer on June 9, 2026 at 5:22 am

    Alright, the problem was that the response for directions was taking too long. I expected the legs[] response to instantly deliver along with the overview_polyline. So I just had to wait till the response came in, this gives me an opportunity to insert a buffer UI.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using Google Direction API. In this i am http://maps.googleapis.com/maps/api/directions/json?origin=Chicago,IL&destination=Los+Angeles,CA&mode=driving,OK&sensor=false . When i
Loving Google Maps API V3, but having difficulty in getting accurate driving directions and
Hi all I'm using Google Directions API and the data returned from a test
I am using the Directions Service of Google Maps V3 API, and I want
I'm using directions for Google Maps V3 API. However I get the javscript error
I have an XML response from the Google Directions API and want to cache
I'm making an app for android, I'm using Google Directions API to get and
I am using the Google directions API in my web application, is there any
I'm using JSON output of Google Directions to parse it in my Android App,
Using Google Apps Script. I know it is not a programming issue, but got

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.