Skip to content

Commit

Permalink
refactor(ios, android): removed deprecated geolocation APIs (#11350)
Browse files Browse the repository at this point in the history
BREAKING CHANGES: Ti.Geoclocation.reverseGeocoder now uses consistent properties postalCode (in place of zipcode) and countryCode (in place of country_code)

Fixes TIMOB-25578
  • Loading branch information
vijaysingh-axway authored and sgtcoolguy committed Dec 9, 2019
1 parent d5ede39 commit 3d32e33
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -321,26 +321,18 @@ private KrollDict buildReverseGeocodeResponse(JSONObject jsonResponse) throws JS

private KrollDict buildAddress(JSONObject place)
{
Log.w(
TAG,
"GeocodedAddress properties country_code, displayAddress, and zipcode are deprecated in SDK 8.0.0 and will be removed in 9.0.0");
Log.w(TAG, "Please replace usage with the respective properties: countryCode, address, and postalCode");
KrollDict address = new KrollDict();
address.put(TiC.PROPERTY_STREET1, place.optString(TiC.PROPERTY_STREET, ""));
address.put(TiC.PROPERTY_STREET, place.optString(TiC.PROPERTY_STREET, ""));
address.put(TiC.PROPERTY_CITY, place.optString(TiC.PROPERTY_CITY, ""));
address.put(TiC.PROPERTY_REGION1, ""); // AdminArea
address.put(TiC.PROPERTY_REGION2, ""); // SubAdminArea
address.put("zipcode", place.optString("zipcode", "")); // TODO: To be removed in SDK 9.0.0!
address.put(TiC.PROPERTY_REGION1, ""); // AdminArea
address.put(TiC.PROPERTY_REGION2, ""); // SubAdminArea
address.put(TiC.PROPERTY_POSTAL_CODE, place.optString("zipcode", ""));
address.put(TiC.PROPERTY_COUNTRY, place.optString(TiC.PROPERTY_COUNTRY, ""));
address.put(TiC.PROPERTY_STATE, place.optString(TiC.PROPERTY_STATE, ""));
// Replace TiC.PROPERTY_COUNTRY_CODE value with "countryCode" in SDK 9.0.0
address.put("countryCode", place.optString(TiC.PROPERTY_COUNTRY_CODE, ""));
address.put(TiC.PROPERTY_COUNTRY_CODE, place.optString(TiC.PROPERTY_COUNTRY_CODE, ""));
address.put(TiC.PROPERTY_COUNTRY_CODE, place.optString("country_code", ""));
address.put(TiC.PROPERTY_LONGITUDE, place.optDouble(TiC.PROPERTY_LONGITUDE, 0.0d));
address.put(TiC.PROPERTY_LATITUDE, place.optDouble(TiC.PROPERTY_LATITUDE, 0.0d));
address.put(TiC.PROPERTY_DISPLAY_ADDRESS, place.optString(TiC.PROPERTY_ADDRESS));
address.put(TiC.PROPERTY_ADDRESS, place.optString(TiC.PROPERTY_ADDRESS));

return address;
Expand Down
3 changes: 1 addition & 2 deletions android/titanium/src/java/org/appcelerator/titanium/TiC.java
Original file line number Diff line number Diff line change
Expand Up @@ -1439,9 +1439,8 @@ public class TiC

/**
* @module.api
* @deprecated Value will be changed to "countryCode" in SDK 9.0.0
*/
public static final String PROPERTY_COUNTRY_CODE = "country_code";
public static final String PROPERTY_COUNTRY_CODE = "countryCode";

/**
* @module.api
Expand Down
3 changes: 3 additions & 0 deletions apidoc/Titanium/Geolocation/Geolocation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1206,6 +1206,7 @@ properties:
platforms: [iphone, ipad]
deprecated:
since: {iphone: "8.0.0", ipad: "8.0.0"}
removed: "9.0.0"

- name: country
summary: Country name.
Expand All @@ -1223,6 +1224,7 @@ properties:
platforms: [android, iphone, ipad]
deprecated:
since: {android: "8.0.0", iphone: "8.0.0", ipad: "8.0.0"}
removed: "9.0.0"

- name: longitude
summary: Longitude of the geocoded point.
Expand All @@ -1240,6 +1242,7 @@ properties:
platforms: [android]
deprecated:
since: {android: "8.0.0"}
removed: "9.0.0"

- name: address
summary: Full address.
Expand Down
5 changes: 2 additions & 3 deletions iphone/Classes/GeolocationModule.m
Original file line number Diff line number Diff line change
Expand Up @@ -143,14 +143,13 @@ - (void)requestSuccess:(NSString *)locationString
BOOL success = [TiUtils boolValue:@"success" properties:event def:YES];
NSMutableDictionary *revisedEvent = [TiUtils dictionaryWithCode:success ? 0 : -1 message:success ? nil : @"error reverse geocoding"];
[revisedEvent setValuesForKeysWithDictionary:event];
// TODO: Remove the zipcode and country_code values after on SDK 9.0.0!
NSArray<NSMutableDictionary *> *places = (NSArray<NSMutableDictionary *> *)revisedEvent[@"places"];
for (NSMutableDictionary *dict in places) {
dict[@"postalCode"] = dict[@"zipcode"];
[dict removeObjectForKey:@"zipcode"];
dict[@"countryCode"] = dict[@"country_code"];
[dict removeObjectForKey:@"country_code"];
}
NSLog(@"[WARN] GeocodedAddress properties country_code and zipcode are deprecated in SDK 8.0.0 and will be removed in 9.0.0");
NSLog(@"[WARN] Please replace usage with the respective properties: countryCode and postalCode");
[callback callWithArguments:@[ revisedEvent ]];
}
}
Expand Down

0 comments on commit 3d32e33

Please sign in to comment.