diff --git a/LMGeocoder/LMAddress.h b/LMGeocoder/LMAddress.h index e17417d..d5d6591 100755 --- a/LMGeocoder/LMAddress.h +++ b/LMGeocoder/LMAddress.h @@ -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. */ diff --git a/LMGeocoder/LMAddress.m b/LMGeocoder/LMAddress.m index 167270b..accd438 100755 --- a/LMGeocoder/LMAddress.m +++ b/LMGeocoder/LMAddress.m @@ -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"; @@ -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] @@ -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; @@ -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"]; diff --git a/LMGeocoder/LMGeocoder.m b/LMGeocoder/LMGeocoder.m index cc56cda..99f2cb0 100755 --- a/LMGeocoder/LMGeocoder.m +++ b/LMGeocoder/LMGeocoder.m @@ -273,31 +273,39 @@ - (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); } @@ -305,19 +313,12 @@ - (void)buildAsynchronousRequestFromURLString:(NSString *)urlString } 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]; } diff --git a/README.md b/README.md index 5563bcb..d185c31 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ +It was archived. Please write to me at kanstantsin.bucha@icloud.com 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.