- Estudar http://code.google.com/apis/maps/documentation/directions/
- Desenhar a rota propriamente dita. Usei http://spitzkoff.com/craig/?p=108
- E o seguinte codigo
-
-(NSArray*)decodePolyline:(NSString*)polyline{
- if (!polyline || [polyline length] == 0) return nil;
- const char* polylinechars = [polyline cStringUsingEncoding:NSUTF8StringEncoding];
- int index = 0;
- NSMutableArray* points = [[NSMutableArray alloc] init];
- int currentLat = 0;
- int currentLng = 0;
- int next5bits;
- int sum;
- int shifter;
-
while (index < [polyline length]) {
- sum = 0;
- shifter = 0;
-
do {
- next5bits = (int)polylinechars[index++] - 63;
- sum |= (next5bits & 31) << shifter;
- shifter += 5;
- if (index >= [polyline length]) break;
- currentLat += (sum & 1) == 1 ? ~(sum >> 1) : (sum >> 1);
- //calculate next longitude
- sum = 0;
- shifter = 0;
-
do {
- next5bits = (int)polylinechars[index++] - 63;
- sum |= (next5bits & 31) << shifter;
- shifter += 5;
- if (index >= [polyline length] && next5bits >= 32) break;
- currentLng += (sum & 1) == 1 ? ~(sum >> 1) : (sum >> 1);
- CLLocation* location = [[CLLocation alloc ] initWithLatitude:(double)currentLat / 100000.0 longitude:(double)currentLng / 100000.0];
- [points addObject:location];
- return points;
[Editado]
Projeto completo Aqui.
Nenhum comentário:
Postar um comentário