Quote:
Originally Posted by sbarham
I'm going to go ahead and push my app with MKReverseGeocoder and complain to apple.
|
Don't! The Google one is infinitely better. So much quicker!
// Show network activity Indicator (no need really as its very quick)
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
// Use Google Service
// OK the code is verbose to illustrate step by step process
// Form the string to make the call, passing in lat long
NSString *urlString = [NSString stringWithFormat:@"http://maps.google.com/maps/geo?q=%lf,%lf&output=csv&sensor=false&key=swizzlec hops", coordinate.latitude,coordinate.longitude];
// Turn it into a URL
NSURL *urlFromURLString = [NSURL URLWithString:urlString];
// Use UTF8 encoding
NSStringEncoding encodingType = NSUTF8StringEncoding;
// reverseGeoString is what comes back with the goodies
NSString *reverseGeoString = [NSString stringWithContentsOfURL:urlFromURLString encoding:encodingType error:nil];
// If it fails it returns nil
if (reverseGeoString != nil)
{
// Break up the tokens returned in the string
// They are comma separated
// The first one is the success code (glass always half full)
// Put this into an array to tokenise
NSArray *listItems = [reverseGeoString
componentsSeparatedByString:@","];
// So the first object in the array is the success code
// 200 means everything is happy
if ([[listItems objectAtIndex:0] isEqualToString:@"200"])
{
// Get the address quality
// We should always have this, but you never know
if ([listItems count] >= 1)
{
NSString *addressQuality =[listItems objectAtIndex:1];
// You can store this somewhere 9 is best, 8 is still great
// You can read Googles doco for an explanation
// e.g. [NSNumber numberWithInteger:[addressQuality intValue]]
}
// Get the address string.
// I am just creating another array to extract the quoted address
NSArray *quotedPart = [reverseGeoString componentsSeparatedByString:@"\""];
// It should always be there as objectAtIndex 1
if ([quotedPart count] >= 2)
{
NSString *address = [quotedPart objectAtIndex:1];
}
}
}
// Hide network activity indicator
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
Sorry about the formatting, I am from a generation before posting code on forums :-)