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

Merge upstream 1.0.7 #1

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
3 changes: 2 additions & 1 deletion LMGeocoder.podspec
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
Pod::Spec.new do |s|

s.name = 'LMGeocoder'
s.version = '1.0.4'
s.version = '1.0.7'
s.summary = 'Simple wrapper for geocoding and reverse geocoding, using both Google Geocoding API and Apple iOS Geocoding Framework.'
s.homepage = 'https://github.com/lminhtm/LMGeocoder'
s.platform = :ios, '7.0'
s.license = {
:type => 'MIT',
:file => 'LICENSE.txt'
Expand Down
30 changes: 20 additions & 10 deletions LMGeocoder/LMAddress.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,47 +23,57 @@
/*!
* The precise street address.
*/
@property (nonatomic, readonly, copy) NSString *thoroughfare;
@property (nonatomic, readonly, copy, nullable) NSString *streetNumber;

/*!
* The named route.
*/
@property (nonatomic, readonly, copy, nullable) NSString *route;

/*!
* The incorporated city or town political entity.
*/
@property (nonatomic, readonly, copy) NSString *locality;
@property (nonatomic, readonly, copy, nullable) NSString *locality;

/*!
* The first-order civil entity below a localit.
*/
@property (nonatomic, readonly, copy) NSString *subLocality;
@property (nonatomic, readonly, copy, nullable) NSString *subLocality;

/*!
* The civil entity below the country level.
*/
@property (nonatomic, readonly, copy) NSString *administrativeArea;
@property (nonatomic, readonly, copy, nullable) NSString *administrativeArea;

/*!
* The additional administrative area information.
*/
@property (nonatomic, readonly, copy, nullable) NSString *subAdministrativeArea;

/*!
* The Postal/Zip code.
*/
@property (nonatomic, readonly, copy) NSString *postalCode;
@property (nonatomic, readonly, copy, nullable) NSString *postalCode;

/*!
* The country name.
*/
@property (nonatomic, readonly, copy) NSString *country;
@property (nonatomic, readonly, copy, nullable) NSString *country;

/*!
* The ISO country code.
*/
@property (nonatomic, readonly, copy) NSString *ISOcountryCode;
@property (nonatomic, readonly, copy, nullable) NSString *ISOcountryCode;

/*!
* The formatted address.
*/
@property (nonatomic, readonly, copy) NSString *formattedAddress;
@property (nonatomic, readonly, copy, nullable) NSString *formattedAddress;

/*!
* An array of NSString containing formatted lines of the address.
*/
@property(nonatomic, readonly, copy) NSArray *lines;
@property (nonatomic, readonly, copy, nullable) NSArray<NSDictionary *> *lines;

/*!
* Initialize with response from server
Expand All @@ -73,6 +83,6 @@
*
* @return object with all data set for use
*/
- (id)initWithLocationData:(id)locationData forServiceType:(int)serviceType;
- (nonnull id)initWithLocationData:(nonnull id)locationData forServiceType:(int)serviceType;

@end
51 changes: 29 additions & 22 deletions LMGeocoder/LMAddress.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,33 @@
#import "LMAddress.h"
#import "LMGeocoder.h"

static NSString * const LMLatitudeKey = @"latitude";
static NSString * const LMLongitudeKey = @"longitude";
static NSString * const LMThoroughfareKey = @"thoroughfare";
static NSString * const LMLocalityKey = @"locality";
static NSString * const LMSubLocalityKey = @"subLocality";
static NSString * const LMAdministrativeAreaKey = @"administrativeArea";
static NSString * const LMPostalCodeKey = @"postalCode";
static NSString * const LMCountryKey = @"country";
static NSString * const LMISOCountryCodeKey = @"ISOcountryCode";
static NSString * const LMFormattedAddressKey = @"formattedAddress";
static NSString * const LMLinesKey = @"lines";

#define allStringKeys @[LMThoroughfareKey, LMLocalityKey, LMSubLocalityKey, \
LMAdministrativeAreaKey, LMPostalCodeKey, LMCountryKey, \
LMISOCountryCodeKey, LMFormattedAddressKey]
static NSString * const LMLatitudeKey = @"latitude";
static NSString * const LMLongitudeKey = @"longitude";
static NSString * const LMStreetNumberKey = @"streetNumber";
static NSString * const LMRouteKey = @"route";
static NSString * const LMLocalityKey = @"locality";
static NSString * const LMSubLocalityKey = @"subLocality";
static NSString * const LMAdministrativeAreaKey = @"administrativeArea";
static NSString * const LMSubAdministrativeAreaKey = @"subAdministrativeArea";
static NSString * const LMPostalCodeKey = @"postalCode";
static NSString * const LMCountryKey = @"country";
static NSString * const LMISOCountryCodeKey = @"ISOcountryCode";
static NSString * const LMFormattedAddressKey = @"formattedAddress";
static NSString * const LMLinesKey = @"lines";

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

@implementation LMAddress

@synthesize coordinate = _coordinate;
@synthesize thoroughfare = _thoroughfare;
@synthesize streetNumber = _streetNumber;
@synthesize route = _route;
@synthesize locality = _locality;
@synthesize subLocality = _subLocality;
@synthesize administrativeArea = _administrativeArea;
@synthesize subAdministrativeArea = _subAdministrativeArea;
@synthesize postalCode = _postalCode;
@synthesize country = _country;
@synthesize ISOcountryCode = _ISOcountryCode;
Expand Down Expand Up @@ -73,10 +77,11 @@ - (void)setAppleLocationData:(id)locationData
NSString *formattedAddress = [lines componentsJoinedByString:@", "];

_coordinate = placemark.location.coordinate;
_thoroughfare = placemark.thoroughfare;
_streetNumber = placemark.thoroughfare;
_locality = placemark.locality;
_subLocality = placemark.subLocality;
_administrativeArea = placemark.administrativeArea;
_subAdministrativeArea = placemark.subAdministrativeArea;
_postalCode = placemark.postalCode;
_country = placemark.country;
_ISOcountryCode = placemark.ISOcountryCode;
Expand All @@ -97,10 +102,12 @@ - (void)setGoogleLocationData:(id)locationData
double lng = [locationDict[@"geometry"][@"location"][@"lng"] doubleValue];

_coordinate = CLLocationCoordinate2DMake(lat, lng);
_thoroughfare = [self component:@"street_number" inArray:lines ofType:@"long_name"];
_streetNumber = [self component:@"street_number" inArray:lines ofType:@"long_name"];
_route = [self component:@"route" inArray:lines ofType:@"long_name"];
_locality = [self component:@"locality" inArray:lines ofType:@"long_name"];
_subLocality = [self component:@"subLocality" inArray:lines ofType:@"long_name"];
_subLocality = [self component:@"sublocality" inArray:lines ofType:@"long_name"];
_administrativeArea = [self component:@"administrative_area_level_1" inArray:lines ofType:@"long_name"];
_subAdministrativeArea = [self component:@"administrative_area_level_2" inArray:lines ofType:@"long_name"];
_postalCode = [self component:@"postal_code" inArray:lines ofType:@"short_name"];
_country = [self component:@"country" inArray:lines ofType:@"long_name"];
_ISOcountryCode = [self component:@"country" inArray:lines ofType:@"short_name"];
Expand Down Expand Up @@ -171,10 +178,10 @@ - (NSUInteger)hash
- (id)initWithCoder:(NSCoder *)aDecoder
{
self = [self init];
if (self) {
if (self)
{
// Load doubles into coordinate
_coordinate = CLLocationCoordinate2DMake([aDecoder decodeDoubleForKey:LMLatitudeKey],
[aDecoder decodeDoubleForKey:LMLongitudeKey]);
_coordinate = CLLocationCoordinate2DMake([aDecoder decodeDoubleForKey:LMLatitudeKey], [aDecoder decodeDoubleForKey:LMLongitudeKey]);

// Load the strings into properties by name
for (NSString *key in allStringKeys) {
Expand Down
44 changes: 37 additions & 7 deletions LMGeocoder/LMGeocoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#import <CoreLocation/CoreLocation.h>
#import "LMAddress.h"

NS_ASSUME_NONNULL_BEGIN

/*!
* LMGeocoder service API.
*/
Expand All @@ -30,7 +32,7 @@ typedef NS_ENUM(NSInteger, LMGeocoderErrorCode){
/*!
* Handler that reports a geocoding response, or error.
*/
typedef void (^LMGeocodeCallback) (NSArray *results, NSError *error);
typedef void (^LMGeocodeCallback) (NSArray<LMAddress *> * _Nullable results, NSError * _Nullable error);

/*!
* Exposes a service for geocoding and reverse geocoding.
Expand All @@ -45,22 +47,22 @@ typedef void (^LMGeocodeCallback) (NSArray *results, NSError *error);
/*!
* To set google API key
*/
@property (nonatomic, strong) NSString *googleAPIKey;
@property (nonatomic, strong, nullable) NSString *googleAPIKey;

/*!
* To set default language, https://developers.google.com/maps/faq#languagesupport
*/
@property (nonatomic, strong) NSString *language;
@property (nonatomic, strong, nullable) NSString *language;

/*!
* To set default country for search, https://en.wikipedia.org/wiki/ISO_3166-1
*/
@property (nonatomic, strong) NSString *country;
@property (nonatomic, strong, nullable) NSString *country;

/*!
* To set default bounds for search, https://en.wikipedia.org/wiki/ISO_3166-1
*/
@property (nonatomic, strong) NSString *bounds;
@property (nonatomic, strong, nullable) NSString *bounds;


/*!
Expand All @@ -85,7 +87,20 @@ typedef void (^LMGeocodeCallback) (NSArray *results, NSError *error);
*/
- (void)geocodeAddressString:(NSString *)addressString
service:(LMGeocoderService)service
completionHandler:(LMGeocodeCallback)handler;
completionHandler:(nullable LMGeocodeCallback)handler;

/*!
* Submits a synchronous forward-geocoding request using the specified string.
*
* @param addressString The string describing the location you want to look up.
* @param service The service API used to geocode.
* @param error The error.
*
* @return The geocode results.
*/
- (nullable NSArray *)geocodeAddressString:(NSString *)addressString
service:(LMGeocoderService)service
error:(NSError **)error;

/*!
* Submits a reverse-geocoding request for the specified coordinate.
Expand All @@ -99,11 +114,26 @@ typedef void (^LMGeocodeCallback) (NSArray *results, NSError *error);
*/
- (void)reverseGeocodeCoordinate:(CLLocationCoordinate2D)coordinate
service:(LMGeocoderService)service
completionHandler:(LMGeocodeCallback)handler;
completionHandler:(nullable LMGeocodeCallback)handler;

/*!
* Submits a synchronous reverse-geocoding request for the specified coordinate.
*
* @param coordinate The coordinate to look up.
* @param service The service API used to geocode.
* @param error The error.
*
* @return The reverse geocode results.
*/
- (nullable NSArray *)reverseGeocodeCoordinate:(CLLocationCoordinate2D)coordinate
service:(LMGeocoderService)service
error:(NSError **)error;

/*!
* Cancels a pending geocoding request.
*/
- (void)cancelGeocode;

@end

NS_ASSUME_NONNULL_END
Loading