If you are working on Google maps API and using routes/directions
this will help you decode route polylines
works on MAC OS X and iPhone SDK
-(NSMutableArray *)decodePolyLine: (NSMutableString *)encoded {
[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 < len) {
NSInteger b;
NSInteger shift = 0;
NSInteger result = 0;
do {
b = [encoded characterAtIndex:index++] - 63;
result |= (b & 0x1f) << shift;
shift += 5;
} while (b >= 0x20);
NSInteger dlat = ((result & 1) ? ~(result >> 1) : (result >> 1));
lat += dlat;
shift = 0;
result = 0;
do {
b = [encoded characterAtIndex:index++] - 63;
result |= (b & 0x1f) << shift;
shift += 5;
} while (b >= 0x20);
NSInteger dlng = ((result & 1) ? ~(result >> 1) : (result >> 1));
lng += dlng;
NSNumber *latitude = [[NSNumber alloc] initWithFloat:lat * 1e-5];
NSNumber *longitude = [[NSNumber alloc] initWithFloat:lng * 1e-5];
CLLocation *loc = [[CLLocation alloc] initWithLatitude:[latitude floatValue] longitude:[longitude floatValue]];
[polyLines addObject:loc];
NSLog(@"%f,%f",[latitude floatValue],[longitude floatValue]);
[loc release];
[latitude release];
[longitude release];
}
return array;
}















hi hasnat,
sorry for commenting on this post, but I needed to contact you – regarding a comment you made on a post over at trailsinthesand.com/exploring-iphone-audio-part-7
Firstly, thanks so much for the lines of code regarding the buttons! very helpful indeed
You seem to say that you managed to get that code working.
I’ve managed to get the audio recording app to build now with no warnings or errors.
I changed the printfs to NSLog outputs and also had to change fsRdPerm to 0×01 in AudioFileOpenURL.
The app installs fine, but on launching it gets to the ‘init’ (where added an NSLog debug message) and then it just closes with no more debug info. :/ hmmm…
I’m building against SDK 3.1.2
Any idea what I might be doing wrong?
I did add the AudioToolbox framework to a new ‘Window-based application’ project too.
Any pointers would be most, most appreciated. Thanks man!
Kosso
wish granted!!
download from http://fkn1337.com/iphone-audio-recording-app-xcodeproj/
u fkn r00l!