Register Login

Talwrn Technology Blog

Jun 24

Written by: S White
Thu, 24 Jun 2010 10:18:04 GMT 

The iPhone MKMapView doesn’t include driving directions as far as I’m aware, but the default map app does. So what do you do when you want driving directions in your own app? The answer is pretty simple and works on v3 and v4. All you need to do is construct a Url for google maps and pass it to the map app:

                UIButton btnDirections = UIButton.FromType(UIButtonType.RoundedRect);
                btnDirections.Frame = new System.Drawing.RectangleF(160, 320, 150, 40);
                btnDirections.SetTitle("Directions...", UIControlState.Normal);
                btnDirections.TitleLabel.TextAlignment = UITextAlignment.Center;
                double slat = (double)appDelegate.myLocation.Coordinate.Latitude;
                double slng = (double)appDelegate.myLocation.Coordinate.Longitude;
                string saddr = slat.ToString() + "," + slng.ToString();
                string daddr = _fishery.FisheryLat.ToString() + "," + _fishery.FisheryLng.ToString();
                btnDirections.TouchDown += delegate {
                    NSUrl url = new NSUrl("http://maps.google.com/maps?saddr=" + saddr + "&daddr=" + daddr);
                    UIApplication.SharedApplication.OpenUrl(url);
                };
                this.View.AddSubview(btnDirections);    

Tags:

Search

Blog

You must be logged in and have permission to create or edit a blog.

Blog Archive

Home · iPhone and Android Apps · Blog · Contact
Terms Of Use  ·  Privacy Statement  ·  Copyright 2013 by Talwrn Technology