Skip to content

Commit a01051f

Browse files
committed
Fixes 182 and removed deprecation warnings. Upgrades compileSDKVersion
1 parent b20737a commit a01051f

File tree

6 files changed

+50
-8
lines changed

6 files changed

+50
-8
lines changed

geocoding_android/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## 4.0.0
2+
3+
* **BREAKING CHANGES**:
4+
* Updates `compileSdk' (compileSdkVersion) from 33 to 34.
5+
* Fixes deprecation build warnings.
6+
17
## 3.0.0
28

39
* **BREAKING CHANGES**:

geocoding_android/android/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ android {
2626
namespace("com.baseflow.geocoding")
2727
}
2828

29-
compileSdkVersion 33
29+
compileSdk 34
3030

3131
compileOptions {
3232
sourceCompatibility JavaVersion.VERSION_1_8
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
org.gradle.jvmargs=-Xmx1536M
2-
android.enableR8=true
32
android.useAndroidX=true
43
android.enableJetifier=true

geocoding_android/android/gradle/wrapper/gradle-wrapper.properties

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
#Tue Jan 30 14:47:38 CET 2024
12
distributionBase=GRADLE_USER_HOME
23
distributionPath=wrapper/dists
4+
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip
35
zipStoreBase=GRADLE_USER_HOME
46
zipStorePath=wrapper/dists
5-
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-all.zip

geocoding_android/android/src/main/java/com/baseflow/geocoding/Geocoding.java

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44
import android.content.Context;
55
import android.location.Address;
66
import android.location.Geocoder;
7-
7+
import android.os.Build;
8+
import androidx.annotation.RequiresApi;
89
import java.io.IOException;
10+
import java.util.ArrayList;
911
import java.util.List;
1012
import java.util.Locale;
1113

@@ -34,10 +36,27 @@ void setLocaleIdentifier(@Nullable Locale locale) {
3436
* @return a list of Address objects. Returns null or empty list if no matches were found or there is no backend service available.
3537
* @throws java.io.IOException if the network is unavailable or any other I/O problem occurs.
3638
*/
39+
@SuppressWarnings("deprecation")
3740
List<Address> placemarkFromAddress(String address) throws IOException {
38-
3941
final Geocoder geocoder = createGeocoder(androidContext, locale);
40-
return geocoder.getFromLocationName(address, 5);
42+
43+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
44+
return getAddressesWithGeocodeListener(geocoder, address, 5);
45+
} else {
46+
return geocoder.getFromLocationName(address, 5);
47+
}
48+
}
49+
50+
@RequiresApi(api = Build.VERSION_CODES.TIRAMISU)
51+
private List<Address> getAddressesWithGeocodeListener(Geocoder geocoder, String address, int maxResults) {
52+
List<Address> addresses = new ArrayList<>();
53+
geocoder.getFromLocationName(address, maxResults, new Geocoder.GeocodeListener() {
54+
@Override
55+
public void onGeocode(List<Address> geocodedAddresses) {
56+
addresses.addAll(geocodedAddresses);
57+
}
58+
});
59+
return addresses;
4160
}
4261

4362
/**
@@ -48,12 +67,29 @@ List<Address> placemarkFromAddress(String address) throws IOException {
4867
* @return a list of Address objects. Returns null or empty list if no matches were found or there is no backend service available.
4968
* @throws IOException if the network is unavailable or any other I/O problem occurs.
5069
*/
70+
@SuppressWarnings("deprecation")
5171
List<Address> placemarkFromCoordinates(
5272
double latitude,
5373
double longitude
5474
) throws IOException {
5575
final Geocoder geocoder = createGeocoder(androidContext, locale);
56-
return geocoder.getFromLocation(latitude, longitude, 5);
76+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
77+
return getLocationWithGeocodeListener(geocoder, latitude, longitude, 5);
78+
} else {
79+
return geocoder.getFromLocation(latitude, longitude, 5);
80+
}
81+
}
82+
83+
@RequiresApi(api = Build.VERSION_CODES.TIRAMISU)
84+
private List<Address> getLocationWithGeocodeListener(Geocoder geocoder, double latitude, double longitude, int maxResults) {
85+
List<Address> addresses = new ArrayList<>();
86+
geocoder.getFromLocation(latitude, longitude, maxResults, new Geocoder.GeocodeListener() {
87+
@Override
88+
public void onGeocode(List<Address> geocodedAddresses) {
89+
addresses.addAll(geocodedAddresses);
90+
}
91+
});
92+
return addresses;
5793
}
5894

5995
private static Geocoder createGeocoder(Context androidContext, @Nullable Locale locale) {

geocoding_android/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: geocoding_android
22
description: A Flutter Geocoding plugin which provides easy geocoding and reverse-geocoding features.
3-
version: 3.0.0
3+
version: 4.0.0
44
repository: https://github.com/baseflow/flutter-geocoding/tree/main/geocoding_android
55
issue_tracker: https://github.com/Baseflow/flutter-geocoding/issues
66

0 commit comments

Comments
 (0)