Baseflow / flutter-geocoding

A Geocoding plugin for Flutter
https://baseflow.com
MIT License
139 stars 71 forks source link

[Feature request]:On Android 13, ISO CountryCode is always empty #246

Open peng093 opened 3 months ago

peng093 commented 3 months ago

Is there already an issue requesting this feature?

Please select affected platform(s)

Use case

countryCode=“”

Proposal

countryCode=“CN”

Specific requirements or considerations

No response

Additional information or context

No response

peng093 commented 3 months ago

There is a similar problem in native Android, such as the United States, which previously returned US, but now returns "54003". If the plugin is written on the basis of native Android, I guess this is the reason

public static String getCountryCode(double lat,double lng) {
        Geocoder geocoder = new Geocoder(Utils.getContext(), Locale.getDefault());
        try {
            List<Address> addresses = geocoder.getFromLocation(lat, lng, 1);
            if (addresses.size() > 0) {
                Address address = addresses.get(0);
                // The numeric code returned in Android 13 is not the country number
                return address.getCountryCode();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return "";
    }