1

I've searched a lot but I didn't find what I need..

I've used a MapKit to display a point of interest in a map and I succeded to do this. But now I would like to allow user to drive from his current location to the point of interest (like Google Maps does).

My question is.. MapKit provide some function that enables user to routing from his current location to the location in the map?

Thanks in advance for your answers.

smanulla
  • 99
  • 3
  • 13
  • I think you should look into `CoreLocation` framework – Pierce Jan 30 '17 at 19:09
  • If you don't mind launching to another app it is pretty easy to launch Apple Maps from your app and send the destination so it automatically gives the user directions from their current location. – chickenparm Jan 30 '17 at 19:18
  • Thanks for the answers! I need that MapKit gives automatically the user directions but maybe it's not possibile, so I think that the solution of @chickenparm is what I will choose. – smanulla Jan 30 '17 at 19:35

1 Answers1

2

You need to create an MKDirectionsRequest. I can't find the code I had for this, but I did find this post:

How to draw a route between two locations using MapKit in Swift?

It includes a link to the year-old tutorial I used.

Community
  • 1
  • 1
dylanthelion
  • 1,760
  • 15
  • 23
  • Thanks for the answer.. But so, I can do this only programmatically? Isn't there a feature in MapKit that automatically gives the user directions like Google Maps do? – smanulla Jan 30 '17 at 19:31
  • Not that I know of. It's also not terribly difficult, if you're okay with the Apple Maps UI, as-is. I remember it being about 20 lines of code, but if you've figured out how to get MapKit and CoreLocation working correctly, you should be able to finish this easily, by the end of the day. – dylanthelion Jan 30 '17 at 19:41
  • Really only about 20 lines? I've been afraid that it could require a lot of time..So, ok, I'll try it! :) thank you. – smanulla Jan 31 '17 at 07:46
  • 1
    Yes. I could be remembering incorrectly, but I think the MKDirectionsRequest object, did most of the work; you just have to feed it all of the location information, set up delegation, and call the correct method. Check the tutorial, and good luck! – dylanthelion Jan 31 '17 at 09:39