title: decode route from google API
body: <p>i am desperately trying to find a way on how to get an Array of all the Coordinates (or a Polyline) from the google API so that I can draw my route on the MKMapView.
  ( By the way, I don´t want to use the RegexKitLite)</p>
  
  <p>As I found elsewhere, this should be the right way to call for the API.</p>
  
  <pre><code>NSString* apiUrlStr = [NSString stringWithFormat:@"http://maps.google.com/maps?output=dragdir&amp;saddr=%@&amp;daddr=%@", saddr, daddr];
  NSURL* apiUrl = [NSURL URLWithString:apiUrlStr];
  
   encodedString = ..... ????   // here i need some code before i can call the following Method
  
  
  [self polylineWithEncodedString:encodedString];
  </code></pre>
  
  <p>and here is a method i found, to get a polyline.</p>
  
  <pre><code>+ (MKPolyline *)polylineWithEncodedString:(NSString *)encodedString {
  const char *bytes = [encodedString UTF8String];
  NSUInteger length = [encodedString lengthOfBytesUsingEncoding:NSUTF8StringEncoding];
  NSUInteger idx = 0;
  
  NSUInteger count = length / 4;
  CLLocationCoordinate2D *coords = calloc(count, sizeof(CLLocationCoordinate2D));
  NSUInteger coordIdx = 0;
  
  float latitude = 0;
  float longitude = 0;
  while (idx &lt; length) {
      char byte = 0;
      int res = 0;
      char shift = 0;
  
      do {
          byte = bytes[idx++] - 63;
          res |= (byte &amp; 0x1F) &lt;&lt; shift;
          shift += 5;
      } while (byte &gt;= 0x20);
  
      float deltaLat = ((res &amp; 1) ? ~(res &gt;&gt; 1) : (res &gt;&gt; 1));
      latitude += deltaLat;
  
      shift = 0;
      res = 0;
  
      do {
          byte = bytes[idx++] - 0x3F;
          res |= (byte &amp; 0x1F) &lt;&lt; shift;
          shift += 5;
      } while (byte &gt;= 0x20);
  
      float deltaLon = ((res &amp; 1) ? ~(res &gt;&gt; 1) : (res &gt;&gt; 1));
      longitude += deltaLon;
  
      float finalLat = latitude * 1E-5;
      float finalLon = longitude * 1E-5;
  
      CLLocationCoordinate2D coord = CLLocationCoordinate2DMake(finalLat, finalLon);
      coords[coordIdx++] = coord;
  
      if (coordIdx == count) {
          NSUInteger newCount = count + 10;
          coords = realloc(coords, newCount * sizeof(CLLocationCoordinate2D));
          count = newCount;
      }
  }
  
  MKPolyline *polyline = [MKPolyline polylineWithCoordinates:coords count:coordIdx];
  free(coords);
  
  return polyline;
  </code></pre>
  
  <p>}</p>