On Apple's built-in Voicemail app, when it finds a phone number it does not recognize in your address book, it displays an approximate location under the number, presumably based on the phone number. How did they do that?? I'd guess there's a large database of area codes and exchange numbers on the phone, each mapping to a city or region name. Does anyone know if this mapping is accessible to apps via a public API?
There's lots of boilerplate code out there for mapping ZIP code to city, but I don't see much that does the same with area code / exchange. Any ideas?
I've created a plist file that has the area codes and locations in it: areacodes.plist. To use it follow these steps:
If you just won't to use the plist file:
1. Add the plist file to your project.
2. Load the file:
NSBundle *bundle = [NSBundle mainBundle];
NSString *plistPath = [bundle pathForResource:@"areacodes" ofType:@"plist"];
NSDictionary *areaCodeDict = [[NSDictionary alloc] initWithContentsOfFile:plistPath];
3. Use the dictionary you've loaded. The keys are the area codes, the values are the locations:
NSString *areaCode = @"801";
NSString *location = [self.areaCodeConversion objectForKey:areaCode];
NSLog(@"%@",location); // prints utah
To use the included class:
1. Add the downloaded folder to your project.
2. Use the included class to access the plist information:
#import "AreaCodes.h"
...
AreaCodes *areaCodes = [[AreaCodes alloc] init];
NSString *location = [areaCodes getLocationForCode:@"801"];
NSLog(@"%@",location);
// prints "Utah"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With