3

I would like to find a simple way to get directions. Is there any way to do this with mapview? Below is my current code.

- (IBAction)goToMap:(id)sender {

[self.view addSubview:self.mapUIView];
[self.mapUIView setFrame:CGRectMake(0, 0, 320, 460)];

self.mapview.mapType = MKMapTypeStandard;

CLLocationCoordinate2D coordinate;
coordinate.latitude = [[self.find lat] floatValue];
coordinate.longitude = [[self.find lng] floatValue];
MKPointAnnotation *annotation = [[MKPointAnnotation alloc] init];

[annotation setCoordinate:coordinate];
[annotation setTitle:[self.find name]];
//[annotation setSubtitle:@"Hello"];
[self.mapview addAnnotation:annotation];
[annotation release];

[self zoomMapViewToFitAnnotations:self.mapview animated:YES];

 }
Boeckm
  • 3,264
  • 4
  • 36
  • 41
  • 1
    Here is the link for the same: You can get everything using it: http://stackoverflow.com/a/11924208/1111384 Hope it works for you. – iCreative Oct 22 '12 at 12:16

4 Answers4

0

You cannot use MapKit for driving directions. It does not support this.

GregJaskiewicz
  • 456
  • 3
  • 11
0

If you want to show the current position of device (like while driving) you have to add CoreLocation framework in your project and should use "updateLocation" method for getting current location but if you want to draw a path between two location you have to use Google Api for this.

Abhinav
  • 191
  • 8
0

If you want to plot directions use: https://github.com/kishikawakatsumi/MapKit-Route-Directions

Sahil Tyagi
  • 363
  • 3
  • 20
  • this code requires ` CLLocationDegrees maxLat = -90; CLLocationDegrees maxLon = -180; CLLocationDegrees minLat = 190; CLLocationDegrees minLon = 280;` how can i get those? –  Oct 22 '12 at 13:39
  • you dont need to make any changes there. Just import the entire library folder to your project. Then import the api.html from resources. Then in the class you want to plot the directions just import all the delegates from MapDirectionsViewController and you are done. – Sahil Tyagi Oct 23 '12 at 07:31
0
CLLocationManager *manager = [[CLLocationManager alloc] init] ;
    CLLocationCoordinate2D currentLocation = [manager location].coordinate;
    CLLocationCoordinate2D coords = CLLocationCoordinate2DMake(37.365502,-94.394531);
    NSString *fromLocation = [NSString stringWithFormat: @"%f,%f",
                      currentLocation.latitude, currentLocation.longitude];
    NSString *toLocation = [NSString stringWithFormat: @"%f,%f",
                                Coordinate.latitude, Coordinate.longitude];
    NSString *url = [NSString stringWithFormat:
                     @"http://maps.google.com/maps?saddr=%@&daddr=%@", fromLocation, fromLocation];

    UIWebView *webView = [[UIWebView alloc]init];
    NSURL *targetURL = [NSURL URLWithString:url];
    NSURLRequest *request = [NSURLRequest requestWithURL:targetURL];
    [webView loadRequest:request];
karthika
  • 4,085
  • 3
  • 21
  • 23