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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T21:10:39+00:00 2026-05-23T21:10:39+00:00

i want to get the route between the two point in the mapkit! i

  • 0

i want to get the route between the two point in the mapkit!
i had done some google work n found this :-http://spitzkoff.com/craig/?p=108

I had used this to display map and pin:-

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationController.navigationBarHidden=NO;
    self.title=@"Map";  
    CLLocationCoordinate2D location; 
    location.latitude=[latLabel doubleValue];
    location.longitude=[longLabel doubleValue]; 
    MKCoordinateRegion region;// = MKCoordinateRegionMakeWithDistance(CLLocationCoordinate2DMake((location.latitude) / 2.0, (location.longitude) / 2.0), 1000.0, 1000.0);
    region.center=location;
    region.span.latitudeDelta =0.1;
    region.span.longitudeDelta =0.1;
    addAnnotation=[[AddressAnnotation alloc] initWithCoordinate:location];      
    NSLog(@"city=mapview=>%@",City);
    NSLog(@"adress=mapview=>%@",Address);   
    addAnnotation.title=City;
    addAnnotation.subtitle=Address;
    [mapView addAnnotation:addAnnotation];  
    [mapView setRegion:region animated:YES];        
    }

-(MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(AddressAnnotation *) annotation
{
    MKPinAnnotationView *annView=[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"currentloc"];
    annView.pinColor=MKPinAnnotationColorRed;   
    annView.draggable=TRUE; 
    annView.animatesDrop=TRUE;
    annView.canShowCallout=YES;
    annView.calloutOffset=CGPointMake(-5,5);
    annView.draggable=TRUE;
    return annView;
}

And annotation class to display the name and address.But how should i have to add more to display the route between the two points.

Please help me.

Thanks in advance

  • 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-05-23T21:10:40+00:00Added an answer on May 23, 2026 at 9:10 pm

    You need to invoke google’s direction services. Read the documentation at

    http://code.google.com/apis/maps/documentation/directions/

    Use the URL that suits your need. Then you would need a JSON or XML parser. JSON has an API, you can download it here

    https://github.com/stig/json-framework/

    You can then get your route polyline points using:

    if (error == nil) {
            NSError *JSONError = nil;
            SBJsonParser *JSONParser = [[SBJsonParser alloc] init];
            id  directions = [JSONParser objectWithString:directionsInJSON error:&JSONError];
            if (JSONError == nil) {
                directions = (NSDictionary*)directions;
                //NSLog(@"Directions: %@",directions);
    
                NSString *status = [directions objectForKey:@"status"];
                if ([status isEqualToString:@"OK"]) {
                    gotDirections = YES;
                    NSArray *routes = [directions objectForKey:@"routes"];
                    NSDictionary *route = [routes objectAtIndex:0];
                    NSDictionary *polylineOverview = [route objectForKey:@"overview_polyline"];
    
                    NSString *polylinePoints = [polylineOverview objectForKey:@"points"];
                    NSArray *decodedPolyline = [self decodePolyLine:polylinePoints];
                }
            }
    }
    //handle elses
    
    - (NSMutableArray *)decodePolyLine: (NSString *)encoded {
        NSInteger len = [encoded length];
        NSInteger index = 0;
        NSMutableArray *array = [[[NSMutableArray alloc] init] autorelease];
        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] autorelease];
            NSNumber *longitude = [[[NSNumber alloc] initWithFloat:lng * 1e-5] autorelease];
            CLLocation *loc = [[[CLLocation alloc] initWithLatitude:[latitude floatValue] longitude:[longitude floatValue]] autorelease];
            [array addObject:loc];
        }
    
        return array;
    }
    
    Then display this array using mkpolyline:
    
    CLLocationCoordinate2D coords[[routes count]];
            for(int i = 0; i < route.count; i++) {        
                CLLocation* location = (CLLocation*)[NSKeyedUnarchiver unarchiveObjectWithData:[routes objectAtIndex:i]];         
                CLLocationCoordinate2D c;
                c.latitude = location.coordinate.latitude;
                c.longitude = location.coordinate.longitude;        
                coords[i] = c; 
    
                Annotation *ann = [[Annotation alloc] initWithTitle:@"" Subtitle:@"" andCoordinate:c];
                [mapView addAnnotation:ann];
                [ann release];
            }
    
            MKPolyline *line = [MKPolyline polylineWithCoordinates:(CLLocationCoordinate2D*)coords count:[route count]];
            [self.mapView addOverlay:line];
    

    Also implement mapView:viewForOverlay delegate method:

    - (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id <MKOverlay>)overlay {
    
        if ([overlay isKindOfClass:[MKPolyline class]]) {
    
            MKPolylineView *polylineView = [[MKPolylineView alloc] initWithPolyline:overlay];
            polylineView.strokeColor = [UIColor redColor];
            polylineView.lineWidth = 1.5;
            return polylineView;
        }
    
        return [[MKOverlayView alloc] initWithOverlay:overlay];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to draw a route between two locations on the map. Something like
I used this function to draw a path between two points. I get the
I want to get started doing some game development using Microsoft's XNA. Part of
I have split some pages in between subdomains and want to do a URL
The GDirections class of Google maps API helped me in displaying the route between
I am trying two draw route between two location,For that I Fetch all the
I want get the time used for a case so I can create an
I want get all of the Geom objects that are related to a certain
I want get as much as possible from Redis + Hiredis + libevent. I'm
I just want get a 2 dimension array of List in c#. In my

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.