2

I am trying to display a route with multiple points in the provided Maps application.

I have figured out how to display a route between two points following this post. I am building a list of multiple points following these directions.

From what I understand, opening a maps.google.com (in iOS) will open the maps application (or Safari if Maps is not available).

The result is the Maps application is still only showing a route between the start and destination. The points added with mrad parameters are not being displayed.

Is it possible to display a route with multiple destinations in iOS at all (without building my own mapping system)?

Community
  • 1
  • 1
Mike D
  • 4,938
  • 6
  • 43
  • 99

3 Answers3

3

To your question, the answer is YES.

But I'll stop trying to look intelligent right there. You're looking at the wrong SO question and answer. What you are looking for is a two step process:

  • use the GMaps Directions API to get a list of waypoints etc
  • draw a line using those points.

Luckily, there's apparently a Github project that does what you need. I didn't use it, so I don't know it's quality, but it's certainly much better than me explaining here how to do it.

https://github.com/kishikawakatsumi/MapKit-Route-Directions

I advise you to look at it.

Cyril Godefroy
  • 1,400
  • 12
  • 15
2

Just wrote a small sample using Google maps api V3 to show directions on iOS 6+ https://github.com/manishnath/iOSPlotRoutesOnMap

manishnath
  • 444
  • 1
  • 3
  • 12
0

Here is the simple And easy code to get Connected route via Multiple location. to get complete project just go on-https://github.com/vikaskumar113/RouteWithMultipleLocation

See the Result

   NSArray *dictionary = @[
                              @{
                                @"Source_lat": @"28.6287",
                                @"Source_lon": @"77.3208",
                                @"Dest_lat": @"28.628454",
                                @"Dest_lon": @"77.376945",
                                @"S_address": @"Vaishali,Delhi",
                                },
                              @{
                                  @"Source_lat": @"28.628454",
                                  @"Source_lon": @"77.376945",
                                  @"Dest_lat": @"28.5529",
                                  @"Dest_lon": @"77.3367",
                                  @"S_address": @"Noida Sec 63",
                                  },
                              @{
                                  @"Source_lat": @"28.5529",
                                  @"Source_lon": @"77.3367",
                                  @"Dest_lat": @"28.6276",
                                  @"Dest_lon": @"77.2784",
                                  @"S_address": @"Noida Sec 44",
                                  },
                               @{
                                  @"Source_lat": @"28.6276",
                                  @"Source_lon": @"77.2784",
                                  @"Dest_lat": @"28.6287",
                                  @"Dest_lon": @"77.3208",
                                  @"S_address": @"Laxmi Nagar,Delhi",
                                  },



                             ];
     for (int i=0; i<dictionary.count; i++) {
    NSDictionary*dict=[dictionary objectAtIndex:i];
    NSString*S_lat=[dict valueForKey:@"Source_lat"];
    NSString*S_lon=[dict valueForKey:@"Source_lon"];
    NSString*D_lat=[dict valueForKey:@"Dest_lat"];
    NSString*D_lon=[dict valueForKey:@"Dest_lon"];
    NSString*address=[dict valueForKey:@"S_address"];

    NSString* apiUrlStr =[NSString stringWithFormat:@"http://maps.googleapis.com/maps/api/directions/json?origin=%@,%@&destination=%@,%@&sensor=false",S_lat,S_lon, D_lat, D_lon
                          ];


NSData *data =[NSData dataWithContentsOfURL:[NSURL URLWithString:apiUrlStr]];
[self performSelectorOnMainThread:@selector(fetchedData:) withObject:data waitUntilDone:YES];

    CLLocationCoordinate2D coord;
    coord.latitude=[S_lat floatValue];
    coord.longitude=[ S_lon floatValue];
    MKCoordinateRegion region1;
    region1.center=coord;
    region1.span.longitudeDelta=0.2 ;
    region1.span.latitudeDelta=0.2;
    [theMapView setRegion:region1 animated:YES];
    MKPointAnnotation *sourceAnnotation = [[MKPointAnnotation alloc]init];
    sourceAnnotation.coordinate=coord;
    sourceAnnotation.title=address;
    [theMapView addAnnotation:sourceAnnotation];

}
Vikas Rajput
  • 1,754
  • 1
  • 14
  • 26