-1

I am showing a map view using MapKit framework in my iPhone application. I am also showing the particular friends list Pin point in map view based on the location they are. I would like to enhance now to showing the road map direction from my location to a particular selected friend location. I know the lat and long for both source and destination, but i have draw route line in road direction, it should be road direction. Could someone help me on this?

Thank you!

iamsult
  • 1,581
  • 1
  • 15
  • 21
Getsy
  • 4,887
  • 16
  • 78
  • 139

2 Answers2

2

MapKit does not expose a means of performing driving directions. So, it's not as simple as asking the map to display a course from location A to location B. You have two options:

1) Integrate with Google's API to get the driving directions, and overlay your own lines onto the MapKit map.

or

2) Simply direct your users out of app and delegate this functionality to the built in Map app.

I have no experience with the former, but the later is very easy. Simply:

CLLocationCoordinate2D location = [[map userLocation] location].coordinate;
double currentLat = location.latitude;
double currentLong = location.longitude;    

NSString *googleUrl = [[NSString alloc] initWithFormat:@"http://maps.google.com/maps?saddr=%f,%f&daddr=%f,%f", currentLat, currentLong, item.latitude, item.longitude];
NSLog(@"%@", googleUrl);
[[UIApplication sharedApplication] openURL:[[NSURL alloc] initWithString:googleUrl]];
Jason Whitehorn
  • 13,585
  • 9
  • 54
  • 68
  • Thanks for it. I am already drawing it using MKOverlayView delegate calls from src to des just as a straight line. I wanted to know, how can i make it "Road Direction Map View" ? – Getsy Feb 24 '12 at 05:12
  • Your question wasn't worded well then, as from the sound of things it appeared that you had no idea how to solve this problem. Knowing from the outset that you already were experimenting with overlays would have been nice to know ;-) Still, point #1 is what you want. – Jason Whitehorn Feb 24 '12 at 05:57
1

Actually there is no api supported by iPhone sdk to draw route on map. There a repo on github which is using google maps api to draw route on map by using map overlay. It has some limitation but you can take help from this repo - https://github.com/kishikawakatsumi/MapKit-Route-Directions

saadnib
  • 11,145
  • 2
  • 33
  • 54
  • Thanks for it. I am already drawing it using MKOverlayView delegate calls from src to des just as a straight line. I wanted to know, how can i make it "Road Direction Map View" ? – Getsy Feb 24 '12 at 05:13