0

How can I draw custom routes between two destinations which is not connecting with a road?

For example, if the Source is The Pizza Factory and the Destination is ATI Solutions I have to draw route like this but there is not roads to connect these two place.

enter image description here

I tried Google's Polylines code but it provides waypoints on the roads only.

NSString *urlString = [NSString stringWithFormat:@"%@?origin=%@,%@&destination=%f,%f&sensor=false&waypoints=optimize:true&mode=driving", @"https://maps.googleapis.com/maps/api/directions/json", getmycurrlat, getmycurrlong, LATI, LONGI];
    NSLog(@"my driving api URL --- %@", urlString);
    NSLog(@"you clicked on button %ld", (long)sender.tag);
    NSURL* url = [[NSURL alloc] initWithString:[NSString stringWithFormat:@"%@", urlString]];
    NSURLResponse* res;
    NSError* err;
    NSData* data = [NSURLConnection sendSynchronousRequest:[[NSURLRequest alloc] initWithURL:url] returningResponse:&res error:&err];
    if (data == nil) {
        return;
    }

    NSDictionary* dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
    NSDictionary* routes = [dic objectForKey:@"routes"][0];
    NSDictionary* route = [routes objectForKey:@"overview_polyline"];
    NSString* overview_route = [route objectForKey:@"points"];

    GMSPath* path = [GMSPath pathFromEncodedPath:overview_route];
    GMSPolyline* polyline = [GMSPolyline polylineWithPath:path];
    polyline.strokeWidth = 5.f;
    polyline.map = self.mapView;

All helps are appreciated!!

Maniganda saravanan
  • 2,188
  • 1
  • 19
  • 35
  • map preferred standard way to make routs is on roads with appropriate space to pass away, what kind of custom route you want to make ? – vaibhav Jan 23 '17 at 07:58
  • There is no road connecting between pizza factory and ATI solution only there is a space between two buildings. Is there any possible way to draw line something like in snapshot? – Maniganda saravanan Jan 23 '17 at 08:01
  • in my exp map will only create route on connected roads if you provide static `lat` `long` prior but there is dynamic way also to create routs bet source to dest while moving [have a look](http://stackoverflow.com/questions/18422826/how-to-track-a-users-location-and-display-the-path-travelled-using-google-maps). – vaibhav Jan 23 '17 at 08:08
  • Is there any way to create custom waypoints? – Maniganda saravanan Jan 23 '17 at 08:10
  • Did you have any luck with this? – FabKremer May 23 '17 at 19:41
  • @Manigandasaravanan thanks for the response! I believe I'll end up using polylines from the GMaps SDK, by wrapping up all coordinates needed to build the custom path and draw some kind of smooth custom path. – FabKremer May 24 '17 at 15:00

1 Answers1

0

Try this is works for me, hope it helps you, i am using AFNetworking to get data

    NSString *url1 = [NSString stringWithFormat:@"https://maps.googleapis.com/maps/api/directions/json?&origin=%@&destination=%@&mode=driving",[NSString stringWithFormat:@"%f,%f",self.locationManager.location.coordinate.latitude,self.locationManager.location.coordinate.longitude],pickLoc];
    AFHTTPRequestOperationManager *operationManager = [AFHTTPRequestOperationManager manager];
    [operationManager POST:url1
                parameters: nil
                   success:^(AFHTTPRequestOperation *operation, id responseObject) {
                       // NSLog(@"JSON: %@", [responseObject description]);

                       NSArray *routesArray = [responseObject objectForKey:@"routes"];

                       GMSPolyline *polyline = nil;

                       if ([routesArray count] > 0)
                       {
                           NSDictionary *routeDict = [routesArray objectAtIndex:0];
                           NSDictionary *routeOverviewPolyline = [routeDict objectForKey:@"overview_polyline"];
                           NSString *points = [routeOverviewPolyline objectForKey:@"points"];
                           GMSPath *path = [GMSPath pathFromEncodedPath:points];
                           polyline = [GMSPolyline polylineWithPath:path];
                           polyline.strokeWidth = 3;
                           polyline.strokeColor = [UIColor colorWithRed:0.9607 green:0.0358 blue:0.1529 alpha:0.6];
                           polyline.map = self.viewMapView;
                       }
                   }
                   failure:^(AFHTTPRequestOperation *operation, NSError *error) {
                       NSLog(@"Error: %@", [error description]);
                   }
     ];
Patel Jigar
  • 2,141
  • 1
  • 23
  • 30