RegisterLogin

Talwrn Technology Blog

Jun24

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:

Your name:
Your email:
(Optional) Email used only to show Gravatar.
Your website:
Title:
Comment:
Security Code
Enter the code shown above in the box below
Add Comment   Cancel 

Search

Blogs

Blog

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

Blog Archive

Home · DotNetNuke Modules · iPhone Apps · Support · Blog · Contact
Terms Of Use  ·  Privacy Statement  ·  Copyright 2011 by Talwrn Technology