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 8473033
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T17:14:16+00:00 2026-06-10T17:14:16+00:00

I’m using mapKit to draw a route from point to point. I did it.

  • 0

I’m using mapKit to draw a route from point to point. I did it.
But i want to get route length NOT the distance as straight line.

nextView.startPoint = [NSString stringWithFormat:@"%f,%f", userLatitude , userLongitude];
nextView.endPoint = [NSString stringWithFormat:@"%f,%f", 30.793636, 31.009641];
[diretions loadWithStartPoint:startPoint endPoint:endPoint options:options];

Aloso i want to give it a mid point to path through.

  • 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-10T17:14:17+00:00Added an answer on June 10, 2026 at 5:14 pm

    To do that you are going to have to use a directions API, preferably Google Directions API. You should look at that link and read it through, Apple does not have a built in direction API. You can send it a request and ask for JSON response, I would use AFNetworking to make like easier (on Github) and JSONKit also on Github for that. Then send a request and parse the JSON response. In the response you need the encoded points, which is a set of many coordinates that basically traces the route. You would then need to display that on an overlay. Here is some sample code, but before you copy and paste this in make sure you read the GDirections API Site, you will understand everything MUCH easier and can learn how to do more:

    // DRAG IN AFNETWORKING FILES AND JSON KIT FILES TO YOUR PROJECT AND ALSO IMPORT THE MAP KIT AND CORE LOCATION FRAMEWORKS
    
    // IMPORT FILES
    
    #import "StringHelper.h"
    #import "JSONKit.h"
    #import "AFJSONRequestOperation.h"
    #import "AFHTTPClient.h"
    #import <MapKit/MapKit.h>
    #import <CoreLocation/CoreLocation.h>
    
    // DECLARE MUTABLE ARRAY IN .H:
    
    NSMutableArray *_path;
    
    // ADD THIS CODE TO WHEN YOU WANT TO REQUEST FOR DIRECTIONS
    
        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];
    
            }
    
        } failure:^(AFHTTPRequestOperation *operation, NSError *error) { }];
    
        [_httpClient enqueueHTTPRequestOperation:operation];
    
        // NOW ADD THE PARSERESPONSE METHOD
    - (void)parseResponse:(NSDictionary *)response {
    
    NSString *status = [response objectForKey: @"status"];
    
    NSArray *routes = [response objectForKey:@"routes"];
    
    NSDictionary *routePath = [routes lastObject];
    
    if (routePath) {
    
        NSString *overviewPolyline = [[routePath objectForKey: @"overview_polyline"] objectForKey:@"points"];
    
        _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];
    }
    
    }
    
    // IMPLEMENTING THE DECODEPOLYLINE METHOD:
    
    -(NSMutableArray *)decodePolyLine:(NSString *)encodedStr {
    
    NSMutableString *encoded = [[NSMutableString alloc] initWithCapacity:[encodedStr length]];
    [encoded appendString:encodedStr];
    [encoded replaceOccurrencesOfString:@"\\\\" withString:@"\\"
                                options:NSLiteralSearch
                                  range:NSMakeRange(0, [encoded length])];
    NSInteger len = [encoded length];
    NSInteger index = 0;
    NSMutableArray *array = [[NSMutableArray alloc] init];
    NSInteger lat=0;
    NSInteger lng=0;
    while (index < len) {
        NSInteger b;
        NSInteger shift = 0;
        NSInteger result = 0;
        do {
            b = [encoded characterAtIndex:index++] - 63;
            result |= (b & 0x1f) << shift;
            shift += 5;
        } while (b >= 0x20);
        NSInteger dlat = ((result & 1) ? ~(result >> 1) : (result >> 1));
        lat += dlat;
        shift = 0;
        result = 0;
        do {
            b = [encoded characterAtIndex:index++] - 63;
            result |= (b & 0x1f) << shift;
            shift += 5;
        } while (b >= 0x20);
        NSInteger dlng = ((result & 1) ? ~(result >> 1) : (result >> 1));
        lng += dlng;
        NSNumber *latitude = [[NSNumber alloc] initWithFloat:lat * 1e-5];
        NSNumber *longitude = [[NSNumber alloc] initWithFloat:lng * 1e-5];
    
        CLLocation *location = [[CLLocation alloc] initWithLatitude:[latitude floatValue] longitude:[longitude floatValue]];
        [array addObject:location];
    }
    
    return array;
    
    }
    
    
    // IMPLEMENTING THE VIEWFOROVERLAY DELEGATE METHOD (MAKE SURE TO SET YOUR MAP VIEW'S DELEGATE TO SELF OR THIS WONT GET CALLED) 
    
    - (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id <MKOverlay>)overlay {
    
    MKPolylineView *polylineView = [[MKPolylineView alloc] initWithPolyline:overlay];
    
    polylineView.strokeColor = [UIColor blueColor];
    polylineView.lineWidth = 5.0;
    polylineView.alpha = 0.7;
    
    return polylineView;
    
    }
    

    And that should get your directional routes up and running!

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

Sidebar

Related Questions

I want to count how many characters a certain string has in PHP, but
I have a French site that I want to parse, but am running into
I want to construct a data frame in an Rcpp function, but when I
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
I am reading a book about Javascript and jQuery and using one of the
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function

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.