1

I have a mapview in my app and i am using apple map's i read here that Mapkit can provide with the direction details as on the Mapview i am using the current location and the lat/long and i want that user can get the driving directions from his current location to the specified lat/long entered by him so that he can get the driving direction route easily on the nextview as i click on the button method or the callout method ...

-(void)getDirection

so the on the next view it should show me the driving directions to that place, please can any one help me out on this i am a beginner and i have never did that much with the mapview, can any one provide me some hint or code snippet that would be very much helpful to me. Or if i can do something thing like this but i don't know how to do that with my project.

enter image description here

nikesh
  • 140
  • 1
  • 15
  • You can only launch the `Map.app` with an give route to start the navigation. You can't do it in your own app unless you code the directions your self. – rckoenes Feb 01 '13 at 12:51
  • @rckoenes : how to code the directions then? .. as i have the current location and the specified lat/long with me .. so just i want now the direction b/w them .. how to do that ? – nikesh Feb 01 '13 at 13:07
  • Well you need to get some kind of database with all the roads and some vert complex code to calculate to the route. Apple does not provide any SDK methods for this. You can use google maps API to get the route, but you will have to check there license if you can use it in that way. – rckoenes Feb 01 '13 at 13:11

2 Answers2

0

use this code first two are destination latitude longitude other are source this code redirect u on apple map and show route if avilable.

  NSString *urlString = [NSString stringWithFormat:@"http://maps.apple.com/?daddr=%f,%f,&saddr=%f,%f",_desLatitude,_desLongitude,_latitude,_longitude];
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString]];
user2155906
  • 149
  • 5
  • thanks for the answer @user2155906 but i have already done that as its a question of february..thanks for the answer anyhow!! below is what my code was. – nikesh Apr 27 '13 at 04:38
  • You are adding a comma before `&saddr` which makes the link wrong. – antf May 19 '13 at 22:29
0
   if (SYSTEM_VERSION_LESS_THAN(@"6.0")) {
       NSString* addr = [NSString stringWithFormat:@"http://maps.apple.com/maps?daddr=%1.6f,%1.6f&saddr=%1.6f,%1.6f",pin_lat,pin_long,mapView.userLocation.coordinate.latitude,mapView.userLocation.coordinate.longitude];

        NSURL* url = [[NSURL alloc] initWithString:[addr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
        [[UIApplication sharedApplication] openURL:url];
    }

    else {
        NSString* addr = [NSString stringWithFormat:@"http://maps.apple.com/maps?daddr=%1.6f,%1.6f&saddr=%1.6f,%1.6f",pin_lat,pin_long,mapView.userLocation.coordinate.latitude,mapView.userLocation.coordinate.longitude];
        NSURL* url = [[NSURL alloc] initWithString:[addr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
        [[UIApplication sharedApplication] openURL:url];


    }   
}
else if ([buttonTitle isEqualToString:@"Google Maps"]) {
    NSLog(@"Other 2 pressed");
    //choose existing

    if (SYSTEM_VERSION_LESS_THAN(@"6.0")) {
        NSString* addr = [NSString stringWithFormat:@"http://maps.google.com/maps?daddr=%1.6f,%1.6f&saddr=%1.6f,%1.6f",pin_lat,pin_long,mapView.userLocation.coordinate.latitude,mapView.userLocation.coordinate.longitude];

        NSURL* url = [[NSURL alloc] initWithString:[addr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
        [[UIApplication sharedApplication] openURL:url];
    }

    else {
        NSString* addr = [NSString stringWithFormat:@"http://maps.google.com/maps?daddr=%1.6f,%1.6f&saddr=%1.6f,%1.6f",pin_lat,pin_long,mapView.userLocation.coordinate.latitude,mapView.userLocation.coordinate.longitude];
        NSURL* url = [[NSURL alloc] initWithString:[addr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
        [[UIApplication sharedApplication] openURL:url];


    }


} 

Where pin_lat and pin_long are float values which contains the value of place .

nikesh
  • 140
  • 1
  • 15