Google Maps iOS SDK, Getting Directions between 2 locations Google Maps iOS SDK, Getting Directions between 2 locations ios ios

Google Maps iOS SDK, Getting Directions between 2 locations


    NSString *urlString = [NSString stringWithFormat:                       @"%@?origin=%f,%f&destination=%f,%f&sensor=true&key=%@",                       @"https://maps.googleapis.com/maps/api/directions/json",                       mapView.myLocation.coordinate.latitude,                       mapView.myLocation.coordinate.longitude,                       destLatitude,                       destLongitude,                       @"Your Google Api Key String"];NSURL *directionsURL = [NSURL URLWithString:urlString];ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:directionsURL];[request startSynchronous];NSError *error = [request error];if (!error) {    NSString *response = [request responseString];    NSLog(@"%@",response);    NSDictionary *json =[NSJSONSerialization JSONObjectWithData:[request responseData] options:NSJSONReadingMutableContainers error:&error];    GMSPath *path =[GMSPath pathFromEncodedPath:json[@"routes"][0][@"overview_polyline"][@"points"]];    GMSPolyline *singleLine = [GMSPolyline polylineWithPath:path];    singleLine.strokeWidth = 7;    singleLine.strokeColor = [UIColor greenColor];    singleLine.map = self.mapView;}else NSLog(@"%@",[request error]);

Note: make Sure Your Google Direction API Sdk Is Enable in Your google developer Console.


It sounds like you are looking for UI Chrome like the Google Maps app has for showing directions. Google Maps SDK for iOS will paint you a map, but you are responsible for the additional navigation chrome.

You can use the Google Directions API to request directions, and then use the encoded path returned from the service to draw a GMSPolyline using GMSPath's pathFromEncodedPath: method.


These lines shows location between a given latitude / longitude and user location;

NSString *googleMapUrlString = [NSString stringWithFormat:@"http://maps.google.com/?saddr=%f,%f&daddr=%@,%@", mapView.userLocation.coordinate.latitude, mapView.userLocation.coordinate.longitude, destinationLatitude, destinationLongtitude];[[UIApplication sharedApplication] openURL:[NSURL URLWithString:googleMapUrlString]];