19

I am developing an application that has two versions. One for web and another for iPhone.

In the web app, I am able to draw a route on the road (drawing the route automatically that follows roads/highways) and off road (draw direct line between two specific points).

Is there an API, for iPhone, that can be used to draw a route on the map? I am able to draw a straight line on the map between two nodes, but i am not able to draw a road map route in iPhone.

I am using iPhone 3.0 and SDK 3.0

Thanks.

Suresh Varma
  • 9,750
  • 1
  • 60
  • 91
Vivek Navadia
  • 574
  • 1
  • 9
  • 19
  • 24
    It seems to me that there is a tendency among people here to downvote questions because they are written in poor English. Anyone who feels the urge to downvote should think two or three times about whether the question is really poorly stated, or if it's just a matter of poor English. At the same time, people who are not fluent in English should make an extra effort to spell check and make sure that their question is intelligible. It's also easier to get good answers that way. – Felixyz Jul 06 '09 at 10:48
  • 10
    Also, instead of downvoting another option is to edit the question to make it more legible. Some questions cannot be repaired, but this question was a perfectly good one, just in need of some tidying. – Kendall Helmstetter Gelner Jul 06 '09 at 14:35
  • I answered a similar question which you can refer [here](http://stackoverflow.com/questions/1494836/mkmapview-route-directions/2941835#2941835) – coffeemate May 31 '10 at 06:55
  • http://iphonegeeksworld.wordpress.com/2010/09/08/drawing-routes-onto-mkmapview-using-unofficial-google-maps-directions-api/ – viral Aug 12 '12 at 08:55

6 Answers6

22

Maybe you want to take a look at Craig Spitzkoff's MapLinesAndAnnotations sample that he recently wrote:

  1. Drawing polyines or routes on a MKMapView (Using Map Kit on the iPhone)
  2. Using MKAnnotation, MKPinAnnotationView and creating a custom MKAnnotationView in an MKMapView
digdog
  • 4,198
  • 1
  • 26
  • 23
10

there's a new API in iOS4 called MKOverlayPathView which does exactly this. MKOverlayPathView

I just wanted to update this post with this information so people get the whole story.

mattjgalloway
  • 34,792
  • 12
  • 100
  • 110
roocell
  • 101
  • 1
  • 2
4
  1. use this url to create a json/xml file http://maps.googleapis.com/maps/api/directions/output?parameters (read code.google.com/apis/maps/documentation/directions/ for more reference)

  2. parse the json/xml file

  3. in routes - legs - steps - polyline you can see points which are in encoded format

  4. decode those points (refer http://fkn1337.com/decode-google-maps-polylines-objective-c/) and make a CLLocationCoordinate2D array

  5. Use

(MKPolyline *)polylineWithCoordinates:(CLLocationCoordinate2D *)coords count:(NSUInteger)count

for creating an MKPolyline object

6 Using MKMapview's addOverlay we can create an overlay with direction

3

Unfortunately, there is no API for that in 3.0. You will probably have to add an overlay on the MKMapView, but that's probably very tedious

drvdijk
  • 5,556
  • 2
  • 29
  • 48
2

A standard way on the iPhone (since there are restrictions expressed in the MapKit license) is to use [[[UIApplication sharedApplication] delegate] openURL:myURL]; to open up the Maps app.

myURL is a 'http://maps.google.com/maps?...' URL (NSURL object) with the subset of options supported in the docs on developer.apple.com. You use the saddr= and daddr= parameters to set the start and end address (or coordinates) of the route, and the user can then see the route and use the Maps app's driving, biking, or walking text directions to travel the route. Perhaps on iPhone 4 GM you will be able to return to your program, but currently opening the URL will terminate your app and start the Maps (or Safari, if Maps is not installed) app instead.

Henrik Erlandsson
  • 3,797
  • 5
  • 43
  • 63
1

Some Addition to Question Might be: HOW CAN ONE GET THOSE COORDINATES DYNAMICALLY, WHICH ARE USED TO DRAW PATH, IN THE EXAMPLE Craig Spitzkoff's MapLinesAndAnnotations sample....? (Getting coordinates between two locations from google maps).

Use the following link: MapWithRoute

Hope, this one would help you draw the route using two user defined location.

viral
  • 4,168
  • 5
  • 43
  • 68