views:

45

answers:

1

Hi, I have read about a number of posts for developers who want to plot out a route on a map on an iPhone but there is no satisfactory answer as how to best achieve this. You can use the Route-Me library, add a layer on top MKMapView or send coordinates to phones map software then you navigate from your application, which in my opinion is bad user experience. None of this solves the problem in a good way.

Some Post writes that there are legal obstacles, others write that it is about licensing money. This must be a very common requirement and thus a common feature to implement. So what is the de-facto standard way to do this?

Can someone with good experience share their insights on this question?

BR //Christoffer

A: 

So I decided to use Apple Developer Technical Support to really clear this out. This is the reply:


Hello,

Thank you for your inquiry to Apple Worldwide Developer Technical Support. I am responding to let you know that I have received your request for technical assistance.

The de-facto standard way of doing this is using the Map application. I realize this is not what you want. You want to stay within your app. The MKMapView API does not give you that level of support when it comes to user directions. You will have to rely on a separate web service to obtain those directions, then plot each lat/long point yourself on the MKMapView. Basically you will need to make an HTTP request to the Google Directions API. The terms require you to display the results on a Google map; since MKMapView shows Google, that should be OK.

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

If you succeed in obtaining driving directions from let say Yahoo or Google service, MKMapView will allow you to plot a visual course using an MKOverlayPathView and MKShapes to draw polygon-like shapes. Apple has a sample called "KMLViewer" found at http://developer.apple.com/library/ios/#samplecode/KMLViewer/Introduction/Intro.html It shows you how to plot points based on KML. The approach is the same since we are dealing with lat/long coordinates.

You may want to consider using the Map application, which would be considerably easier. All you need is this:

// for lat/long directions NSString *urlString1 = @"http://maps.google.com/maps?daddr=37.324885,-122.032378&saddr=37.332094,-122.03124";

// for address directions NSString *urlString2 = @"http://maps.google.com/maps?f=d&source=s_d&saddr=1+Infinite+Loop,+Cupertino,+CA+95014&daddr=Mandarin+Gourmet,+Cupertino,+CA&hl=en&geocode=FcajOQIdYvO5-Ckbd16TtrWPgDFAc4Pi50E92A%3BFZ2GOQIdLe65-CHRv0sTH7YegykLqKn9rbWPgDGUnqKbIqi1Bg&mra=ls&sll=37.325567,-122.032989&sspn=0.007243,0.007285&ie=UTF8&ll=37.328195,-122.031466&spn=0.007243,0.007285&z=17";

[[UIApplication sharedApplication] openURL: [NSURL URLWithString: urlString1]];

SECOND E-MAIL:

Just to be clear in my last e-mail about the terms for using Google services. Google requires you to display the route results on a Google map, which MKMapView uses. However, I would double-check Apple's own T&Cs regarding the use of external services like user directions on MKMapView itself. I don't want you do go down a path only to find legal restrictions along the way.


Christofffer