Skip to content

Commit

Permalink
Merge branch 'master' into track-verified-callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
nickpatrick authored May 31, 2024
2 parents acd7752 + 700d565 commit f97ef49
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 18 deletions.
16 changes: 16 additions & 0 deletions Example/Example/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,26 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
Radar.geocode(address: "20 jay st brooklyn") { (status, addresses) in
print("Geocode: status = \(Radar.stringForStatus(status)); coordinate = \(String(describing: addresses?.first?.coordinate))")
}

Radar.geocode(address: "20 jay st brooklyn", layers: ["place", "locality"], countries: ["US", "CA"]) { (status, addresses) in
print("Geocode: status = \(Radar.stringForStatus(status)); coordinate = \(String(describing: addresses?.first?.coordinate))")
}

Radar.reverseGeocode { (status, addresses) in
print("Reverse geocode: status = \(Radar.stringForStatus(status)); formattedAddress = \(String(describing: addresses?.first?.formattedAddress))")
}

Radar.reverseGeocode(layers: ["locality", "state"]) { (status, addresses) in
print("Reverse geocode: status = \(Radar.stringForStatus(status)); formattedAddress = \(String(describing: addresses?.first?.formattedAddress))")
}

Radar.reverseGeocode(location: CLLocation(latitude: 40.70390, longitude: -73.98670)) { (status, addresses) in
print("Reverse geocode: status = \(Radar.stringForStatus(status)); formattedAddress = \(String(describing: addresses?.first?.formattedAddress))")
}

Radar.reverseGeocode(location: CLLocation(latitude: 40.70390, longitude: -73.98670), layers: ["locality", "state"]) { (status, addresses) in
print("Reverse geocode: status = \(Radar.stringForStatus(status)); formattedAddress = \(String(describing: addresses?.first?.formattedAddress))")
}

Radar.ipGeocode { (status, address, proxy) in
print("IP geocode: status = \(Radar.stringForStatus(status)); country = \(String(describing: address?.countryCode)); city = \(String(describing: address?.city)); proxy = \(proxy)")
Expand Down
4 changes: 2 additions & 2 deletions RadarSDK.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1005,7 +1005,7 @@
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
MARKETING_VERSION = 3.11.0;
MARKETING_VERSION = 3.11.2;
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
ONLY_ACTIVE_ARCH = YES;
Expand Down Expand Up @@ -1063,7 +1063,7 @@
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
MARKETING_VERSION = 3.11.0;
MARKETING_VERSION = 3.11.2;
MTL_ENABLE_DEBUG_INFO = NO;
MTL_FAST_MATH = YES;
OTHER_CFLAGS = "-fembed-bitcode";
Expand Down
39 changes: 39 additions & 0 deletions RadarSDK/Include/Radar.h
Original file line number Diff line number Diff line change
Expand Up @@ -954,6 +954,21 @@ Gets the device's current location, then searches for geofences near that locati
*/
+ (void)geocodeAddress:(NSString *_Nonnull)query completionHandler:(RadarGeocodeCompletionHandler)completionHandler NS_SWIFT_NAME(geocode(address:completionHandler:));

/**
Geocodes an address, converting address to coordinates.
@param query The address to geocode.
@param layers Optional layer filters.
@param countries Optional country filters. A string array of unique 2-letter country codes.
@param completionHandler A completion handler.
@see https://radar.com/documentation/api#forward-geocode
*/
+ (void)geocodeAddress:(NSString *)query
layers:(NSArray<NSString *> *_Nullable)layers
countries:(NSArray<NSString *> *_Nullable)countries
completionHandler:(RadarGeocodeCompletionHandler)completionHandler NS_SWIFT_NAME(geocode(address:layers:countries:completionHandler:));

/**
Gets the device's current location, then reverse geocodes that location, converting coordinates to address.
Expand All @@ -963,6 +978,17 @@ Gets the device's current location, then searches for geofences near that locati
*/
+ (void)reverseGeocodeWithCompletionHandler:(RadarGeocodeCompletionHandler)completionHandler NS_SWIFT_NAME(reverseGeocode(completionHandler:));

/**
Gets the device's current location, then reverse geocodes that location, converting coordinates to address.
@param completionHandler A completion handler.
@param layers Optional layer filters.
@see https://radar.com/documentation/api#reverse-geocode
*/
+ (void)reverseGeocodeWithLayers:(NSArray<NSString *> *_Nullable)layers
completionHandler:(RadarGeocodeCompletionHandler)completionHandler NS_SWIFT_NAME(reverseGeocode(layers:completionHandler:));

/**
Reverse geocodes a location, converting coordinates to address.
Expand All @@ -974,6 +1000,19 @@ Gets the device's current location, then searches for geofences near that locati
+ (void)reverseGeocodeLocation:(CLLocation *_Nonnull)location
completionHandler:(RadarGeocodeCompletionHandler)completionHandler NS_SWIFT_NAME(reverseGeocode(location:completionHandler:));

/**
Reverse geocodes a location, converting coordinates to address.
@param location The location to reverse geocode.
@param layers Optional layer filters.
@param completionHandler A completion handler.
@see https://radar.com/documentation/api#reverse-geocode
*/
+ (void)reverseGeocodeLocation:(CLLocation *)location
layers:(NSArray<NSString *> *_Nullable)layers
completionHandler:(RadarGeocodeCompletionHandler)completionHandler NS_SWIFT_NAME(reverseGeocode(location:layers:completionHandler:));

/**
Geocodes the device's current IP address, converting IP address to partial address.
Expand Down
35 changes: 24 additions & 11 deletions RadarSDK/Radar.m
Original file line number Diff line number Diff line change
Expand Up @@ -850,18 +850,31 @@ + (void)autocompleteQuery:(NSString *_Nonnull)query near:(CLLocation *_Nullable)

#pragma mark - Geocoding

+ (void)geocodeAddress:(NSString *)query completionHandler:(RadarGeocodeCompletionHandler)completionHandler {
+ (void)geocodeAddress:(NSString *)query
layers:(NSArray<NSString *> *_Nullable)layers
countries:(NSArray<NSString *> *_Nullable)countries
completionHandler:(RadarGeocodeCompletionHandler)completionHandler {
[[RadarLogger sharedInstance] logWithLevel:RadarLogLevelInfo type:RadarLogTypeSDKCall message:@"geocode()"];
[[RadarAPIClient sharedInstance] geocodeAddress:query
layers:layers
countries:countries
completionHandler:^(RadarStatus status, NSDictionary *_Nullable res, NSArray<RadarAddress *> *_Nullable addresses) {
[RadarUtils runOnMainThread:^{
completionHandler(status, addresses);
}];
}];
}

+ (void)geocodeAddress:(NSString *)query completionHandler:(RadarGeocodeCompletionHandler)completionHandler {
[Radar geocodeAddress:query layers:nil countries:nil completionHandler:completionHandler];
}

+ (void)reverseGeocodeWithCompletionHandler:(RadarGeocodeCompletionHandler)completionHandler {
[[RadarLogger sharedInstance] logWithLevel:RadarLogLevelInfo type:RadarLogTypeSDKCall message:@"reverseGeocode()"];
[Radar reverseGeocodeWithLayers:nil completionHandler:completionHandler];
}

+ (void)reverseGeocodeWithLayers:(NSArray<NSString *> *_Nullable)layers
completionHandler:(RadarGeocodeCompletionHandler)completionHandler {
[[RadarLocationManager sharedInstance] getLocationWithCompletionHandler:^(RadarStatus status, CLLocation *_Nullable location, BOOL stopped) {
if (status != RadarStatusSuccess) {
if (completionHandler) {
Expand All @@ -872,28 +885,28 @@ + (void)reverseGeocodeWithCompletionHandler:(RadarGeocodeCompletionHandler)compl

return;
}

[[RadarAPIClient sharedInstance] reverseGeocodeLocation:location
completionHandler:^(RadarStatus status, NSDictionary *_Nullable res, NSArray<RadarAddress *> *_Nullable addresses) {
if (completionHandler) {
[RadarUtils runOnMainThread:^{
completionHandler(status, addresses);
}];
}
}];
[Radar reverseGeocodeLocation:location layers:layers completionHandler:completionHandler];
}];
}

+ (void)reverseGeocodeLocation:(CLLocation *)location completionHandler:(RadarGeocodeCompletionHandler)completionHandler {
[Radar reverseGeocodeLocation:location layers:nil completionHandler:completionHandler];
}

+ (void)reverseGeocodeLocation:(CLLocation *)location
layers:(NSArray<NSString *> *_Nullable)layers
completionHandler:(RadarGeocodeCompletionHandler)completionHandler {
[[RadarLogger sharedInstance] logWithLevel:RadarLogLevelInfo type:RadarLogTypeSDKCall message:@"reverseGeocode()"];
[[RadarAPIClient sharedInstance] reverseGeocodeLocation:location
layers:layers
completionHandler:^(RadarStatus status, NSDictionary *_Nullable res, NSArray<RadarAddress *> *_Nullable addresses) {
if (completionHandler) {
[RadarUtils runOnMainThread:^{
completionHandler(status, addresses);
}];
}
}];

}

+ (void)ipGeocodeWithCompletionHandler:(RadarIPGeocodeCompletionHandler)completionHandler {
Expand Down
11 changes: 8 additions & 3 deletions RadarSDK/RadarAPIClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,14 @@ typedef void (^_Nonnull RadarSyncLogsAPICompletionHandler)(RadarStatus status);

- (void)validateAddress:(RadarAddress *_Nonnull)address completionHandler:(RadarValidateAddressAPICompletionHandler _Nonnull)completionHandler;

- (void)geocodeAddress:(NSString *_Nonnull)query completionHandler:(RadarGeocodeAPICompletionHandler _Nonnull)completionHandler;

- (void)reverseGeocodeLocation:(CLLocation *_Nonnull)location completionHandler:(RadarGeocodeAPICompletionHandler _Nonnull)completionHandler;
- (void)geocodeAddress:(NSString *_Nonnull)query
layers:(NSArray<NSString *> *_Nullable)layers
countries:(NSArray<NSString *> *_Nullable)countries
completionHandler:(RadarGeocodeAPICompletionHandler _Nonnull)completionHandler;

- (void)reverseGeocodeLocation:(CLLocation *_Nonnull)location
layers:(NSArray<NSString *> *_Nullable)layers
completionHandler:(RadarGeocodeAPICompletionHandler _Nonnull)completionHandler;

- (void)ipGeocodeWithCompletionHandler:(RadarIPGeocodeAPICompletionHandler _Nonnull)completionHandler;

Expand Down
18 changes: 16 additions & 2 deletions RadarSDK/RadarAPIClient.m
Original file line number Diff line number Diff line change
Expand Up @@ -1088,14 +1088,23 @@ - (void)validateAddress:(RadarAddress *)address completionHandler:(RadarValidate
}];
}

- (void)geocodeAddress:(NSString *)query completionHandler:(RadarGeocodeAPICompletionHandler)completionHandler {
- (void)geocodeAddress:(NSString *)query
layers:(NSArray<NSString *> *_Nullable)layers
countries:(NSArray<NSString *> *_Nullable)countries
completionHandler:(RadarGeocodeAPICompletionHandler)completionHandler {
NSString *publishableKey = [RadarSettings publishableKey];
if (!publishableKey) {
return completionHandler(RadarStatusErrorPublishableKey, nil, nil);
}

NSMutableString *queryString = [NSMutableString new];
[queryString appendFormat:@"query=%@", query];
if (layers && layers.count > 0) {
[queryString appendFormat:@"&layers=%@", [layers componentsJoinedByString:@","]];
}
if (countries && countries.count > 0) {
[queryString appendFormat:@"&country=%@", [countries componentsJoinedByString:@","]];
}

NSString *host = [RadarSettings host];
NSString *url = [NSString stringWithFormat:@"%@/v1/geocode/forward?%@", host, queryString];
Expand Down Expand Up @@ -1125,14 +1134,19 @@ - (void)geocodeAddress:(NSString *)query completionHandler:(RadarGeocodeAPICompl
}];
}

- (void)reverseGeocodeLocation:(CLLocation *)location completionHandler:(RadarGeocodeAPICompletionHandler)completionHandler {
- (void)reverseGeocodeLocation:(CLLocation *)location
layers:(NSArray<NSString *> *_Nullable)layers
completionHandler:(RadarGeocodeAPICompletionHandler)completionHandler {
NSString *publishableKey = [RadarSettings publishableKey];
if (!publishableKey) {
return completionHandler(RadarStatusErrorPublishableKey, nil, nil);
}

NSMutableString *queryString = [NSMutableString new];
[queryString appendFormat:@"coordinates=%.06f,%.06f", location.coordinate.latitude, location.coordinate.longitude];
if (layers && layers.count > 0) {
[queryString appendFormat:@"&layers=%@", [layers componentsJoinedByString:@","]];
}

NSString *host = [RadarSettings host];
NSString *url = [NSString stringWithFormat:@"%@/v1/geocode/reverse?%@", host, queryString];
Expand Down

0 comments on commit f97ef49

Please sign in to comment.