Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add postalTown property #21

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions LMGeocoder/LMAddress.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@
*/
@property (nonatomic, readonly, copy, nullable) NSString *route;

/*!
* Sometime it incorporated known name of a city or town ( London ).
*/

@property (nonatomic, readonly, copy, nullable) NSString *postalTown;

/*!
* The incorporated city or town political entity.
*/
Expand Down
5 changes: 4 additions & 1 deletion LMGeocoder/LMAddress.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
static NSString * const LMLongitudeKey = @"longitude";
static NSString * const LMStreetNumberKey = @"streetNumber";
static NSString * const LMRouteKey = @"route";
static NSString * const LMPostalTownKey = @"postal_town";
static NSString * const LMLocalityKey = @"locality";
static NSString * const LMSubLocalityKey = @"subLocality";
static NSString * const LMAdministrativeAreaKey = @"administrativeArea";
Expand All @@ -24,7 +25,7 @@
static NSString * const LMFormattedAddressKey = @"formattedAddress";
static NSString * const LMLinesKey = @"lines";

#define allStringKeys @[LMStreetNumberKey, LMRouteKey, LMLocalityKey, LMSubLocalityKey, \
#define allStringKeys @[LMStreetNumberKey, LMRouteKey, LMPostalTownKey, LMLocalityKey, LMSubLocalityKey, \
LMAdministrativeAreaKey, LMSubAdministrativeAreaKey, LMNeighborhoodKey, LMPostalCodeKey, \
LMCountryKey, LMISOCountryCodeKey, LMFormattedAddressKey]

Expand All @@ -33,6 +34,7 @@ @implementation LMAddress
@synthesize coordinate = _coordinate;
@synthesize streetNumber = _streetNumber;
@synthesize route = _route;
@synthesize postalTown = _postalTown;
@synthesize locality = _locality;
@synthesize subLocality = _subLocality;
@synthesize administrativeArea = _administrativeArea;
Expand Down Expand Up @@ -108,6 +110,7 @@ - (void)setGoogleLocationData:(id)locationData
_coordinate = CLLocationCoordinate2DMake(lat, lng);
_streetNumber = [self component:@"street_number" inArray:addressComponents ofType:@"long_name"];
_route = [self component:@"route" inArray:addressComponents ofType:@"long_name"];
_postalTown = [self component:LMPostalTownKey inArray:addressComponents ofType:@"long_name"];
_locality = [self component:@"locality" inArray:addressComponents ofType:@"long_name"];
_subLocality = [self component:@"sublocality" inArray:addressComponents ofType:@"long_name"];
_administrativeArea = [self component:@"administrative_area_level_1" inArray:addressComponents ofType:@"long_name"];
Expand Down
57 changes: 29 additions & 28 deletions LMGeocoder/LMGeocoder.m
Original file line number Diff line number Diff line change
Expand Up @@ -273,51 +273,52 @@ - (void)buildAsynchronousRequestFromURLString:(NSString *)urlString
NSURLSession *session = [NSURLSession sessionWithConfiguration:configuration];
self.googleGeocoderTask = [session dataTaskWithRequest:request
completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {

if (!error && data)
{
// Request successful --> Parse response to JSON
NSError *parsingError = nil;
NSDictionary *result = [NSJSONSerialization JSONObjectWithData:data
options:NSJSONReadingAllowFragments
error:&parsingError];
if (!parsingError && result)
dispatch_async(dispatch_get_main_queue(), ^{
if (!error && data)
{
// Parse successful --> Check status value
NSString *status = [result valueForKey:@"status"];
if ([status isEqualToString:@"OK"])
// Request successful --> Parse response to JSON
NSError *parsingError = nil;
NSDictionary *result = [NSJSONSerialization JSONObjectWithData:data
options:NSJSONReadingAllowFragments
error:&parsingError];
if (!parsingError && result)
{
// Status OK --> Parse response results
NSArray *locationDicts = [result objectForKey:@"results"];
NSArray *finalResults = [self parseGeocodingResponseResults:locationDicts service:kLMGeocoderGoogleService];

if (handler) {
handler(finalResults, nil);
// Parse successful --> Check status value
NSString *status = [result valueForKey:@"status"];
if ([status isEqualToString:@"OK"])
{
// Status OK --> Parse response results
NSArray *locationDicts = [result objectForKey:@"results"];
NSArray *finalResults = [self parseGeocodingResponseResults:locationDicts service:kLMGeocoderGoogleService];

if (handler) {
handler(finalResults, nil);
}
}
else
{
// Other statuses --> Return error
if (handler) {
handler(nil, error);
}
}
}
else
{
// Other statuses --> Return error
// Parse failed --> Return error
if (handler) {
handler(nil, error);
}
}
}
else
{
// Parse failed --> Return error
// Request failed --> Return error
if (handler) {
handler(nil, error);
}
}
}
else
{
// Request failed --> Return error
if (handler) {
handler(nil, error);
}
}
});
}];
[self.googleGeocoderTask resume];
}
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
It was archived. Please write to me at [email protected] in case any issues occur.

LMGeocoder
==============
LMGeocoder is a simple wrapper for geocoding and reverse geocoding dynamically from user input. It is blocked-based geocoder, use both Google Geocoding API and Apple iOS Geocoding Framework.
Expand Down