Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here The way in which I am able to draw direction between two points(Location).</p> <hr> <blockquote> <blockquote> <p>First of all download GoogleMap sdk from <a href="https://developers.google.com/maps/documentation/ios/releases" rel="nofollow">this</a> link and integrate into your application.</p> </blockquote> </blockquote> <p>Now API key required and you can create as par given guidelines on <a href="https://developers.google.com/maps/documentation/ios/start#the_google_maps_api_key" rel="nofollow">this</a> link.</p> <p>Below are Code that draw direction on google map between two location.</p> <hr> <pre><code>-(NSArray*) calculateRoutesFrom:(CLLocationCoordinate2D) f to: (CLLocationCoordinate2D) t { NSString* saddr = [NSString stringWithFormat:@"%f,%f", f.latitude, f.longitude]; NSString* daddr = [NSString stringWithFormat:@"%f,%f", t.latitude, t.longitude]; NSURL *url=[NSURL URLWithString:[NSString stringWithFormat:@"http://maps.googleapis.com/maps/api/directions/json?origin=%@&amp;destination=%@&amp;sensor=false&amp;avoid=highways&amp;mode=driving",saddr,daddr]]; NSError *error=nil; NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init] ; [request setURL:url]; [request setHTTPMethod:@"POST"]; NSURLResponse *response = nil; NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&amp;response error: &amp;error]; NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding]; NSDictionary * dic = [NSJSONSerialization JSONObjectWithData:[responseString dataUsingEncoding:NSUTF8StringEncoding] options:NSJSONWritingPrettyPrinted error:nil]; return [self decodePolyLine:[self parseResponse:dic]]; } - (NSString *)parseResponse:(NSDictionary *)response { NSArray *routes = [response objectForKey:@"routes"]; NSDictionary *route = [routes lastObject]; if (route) { NSString *overviewPolyline = [[route objectForKey: @"overview_polyline"] objectForKey:@"points"]; return overviewPolyline; } return @""; } -(NSMutableArray *)decodePolyLine:(NSString *)encodedStr { NSMutableString *encoded = [[NSMutableString alloc] initWithCapacity:[encodedStr length]]; [encoded appendString:encodedStr]; [encoded replaceOccurrencesOfString:@"\\\\" withString:@"\\" options:NSLiteralSearch range:NSMakeRange(0, [encoded length])]; NSInteger len = [encoded length]; NSInteger index = 0; NSMutableArray *array = [[NSMutableArray alloc] init]; NSInteger lat=0; NSInteger lng=0; while (index &lt; len) { NSInteger b; NSInteger shift = 0; NSInteger result = 0; do { b = [encoded characterAtIndex:index++] - 63; result |= (b &amp; 0x1f) &lt;&lt; shift; shift += 5; } while (b &gt;= 0x20); NSInteger dlat = ((result &amp; 1) ? ~(result &gt;&gt; 1) : (result &gt;&gt; 1)); lat += dlat; shift = 0; result = 0; do { b = [encoded characterAtIndex:index++] - 63; result |= (b &amp; 0x1f) &lt;&lt; shift; shift += 5; } while (b &gt;= 0x20); NSInteger dlng = ((result &amp; 1) ? ~(result &gt;&gt; 1) : (result &gt;&gt; 1)); lng += dlng; NSNumber *latitude = [[NSNumber alloc] initWithFloat:lat * 1e-5]; NSNumber *longitude = [[NSNumber alloc] initWithFloat:lng * 1e-5]; CLLocation *location = [[CLLocation alloc] initWithLatitude: [latitude floatValue] longitude:[longitude floatValue]]; [array addObject:location]; } return array; } - (void)loadMapViewWithDirection { float lat = 23.050671; float lng = 72.541351; GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:lat longitude:lng zoom:10]; GMSMapView * mapView = [GMSMapView mapWithFrame:CGRectMake(0, 75, 320, self.view.frame.size.height-kHeaderRect.size.height) camera:camera]; self.mapView.myLocationEnabled = YES; float sourceLatitude = 23.050671; float sourceLongitude = 72.541351; float destLatitude = 23.036138; float destLongitude = 72.603836; GMSMarker *sourceMarker = [[GMSMarker alloc] init]; marker.position = CLLocationCoordinate2DMake(sourceLatitude, sourceLongitude); marker.map = self.mapView; GMSMarker *destMarker = [[GMSMarker alloc] init]; marker.position = CLLocationCoordinate2DMake(destLatitude, destLongitude); marker.map = self.mapView; self.mapView.delegate = self; [self drawDirection:CLLocationCoordinate2DMake(sourceLatitude, sourceLongitude) and:CLLocationCoordinate2DMake(destLatitude, destLongitude)]; [self.view addSubview:self.mapView]; } - (void) drawDirection:(CLLocationCoordinate2D)source and:(CLLocationCoordinate2D) dest { GMSPolyline *polyline = [[GMSPolyline alloc] init]; GMSMutablePath *path = [GMSMutablePath path]; NSArray * points = [self calculateRoutesFrom:source to:dest]; NSInteger numberOfSteps = points.count; for (NSInteger index = 0; index &lt; numberOfSteps; index++) { CLLocation *location = [points objectAtIndex:index]; CLLocationCoordinate2D coordinate = location.coordinate; [path addCoordinate:coordinate]; } polyline.path = path; polyline.strokeColor = [UIColor redColor]; polyline.strokeWidth = 2.f; polyline.map = self.mapView; // Copy the previous polyline, change its color, and mark it as geodesic. polyline = [polyline copy]; polyline.strokeColor = [UIColor greenColor]; polyline.geodesic = YES; polyline.map = self.mapView; } - (void)viewDidLoad { [super viewDidLoad]; [self loadMapViewWithDirection]; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload