I’ve spent an entire day reading Apple Docs, scouring the web looking at Objective-C code and C# regarding mapping with a view to implementing it in my App. I’m talking about iOS 6 and 7 and in particular Apple Maps.

If you want to use Google Maps be aware that you cannot implement Turn by Turn according to their Google Maps T & C. You must not use the Service or Content with any products, systems, or applications for or in connection with any of the following: “(i) real time navigation or route guidance, including but not limited to turn-by-turn route guidance that is synchronized to the position of a user’s sensor-enabled device.“.

So it’s Apple Maps and MapKit which is jolly good. Now Apple have a lovely Maps app and you can invoke it from your App but that pushes your App into the background. There’s no way to use the excellent Apple Maps Turn By Turn within your App.

using MonoTouch.MapKit;
using MonoTouch.CoreLocation;
...
GeoCoder.GeocodeAddress("224 Richmond Road, Leytonstone,E11 4DA", ( placemarks, error) =>
    {
        try
        {
            var coordinate = placemarks[0].Location.Coordinate;
            var placeMark = new MKPlacemark(coordinate,null);
            var mapItem = new MKMapItem(placeMark);

            mapItem.Name = "Where we are going to.";
            mapItem.PhoneNumber = "0203 555 9999";  // Not a real number (I hope!)

            var launchOptions = new MKLaunchOptions();
            launchOptions.DirectionsMode = MKDirectionsMode.Driving;
            launchOptions.MapType=MKMapType.Standard;
            launchOptions.ShowTraffic = false;

            mapItem.OpenInMaps(launchOptions);
        }
        catch (Exception ex)
        {
            var erroralert = new UIAlertView("Location could not be found", "", null, "Ok", null);
            erroralert.Show();
        }                        
    });

That converts the old address (I once lived there – 12 years ago) to coordinates that are passed, along with the Name and Phonenumber to the Apple iPhone Maps App. Here’s what that code produces (dumped from my iPhone).

directions

The Other Way

This involves creating a MapView etc and then asking Apple for directions between points a and b. Rather than explain further I point you to Blake Davidson who has done that (in C#).

Leave a Reply

Post Navigation