Skip to content

Instantly share code, notes, and snippets.

@dmitriigriazin
Created December 3, 2019 07:05
Show Gist options
  • Save dmitriigriazin/248c9226e1a1f1e578414422f19df304 to your computer and use it in GitHub Desktop.
Save dmitriigriazin/248c9226e1a1f1e578414422f19df304 to your computer and use it in GitHub Desktop.
public final class AdvancedGeoCoder {
private final Geocoder geocoder;
private final List<Address> addressList = new ArrayList<>();
private @GeocoderType
int coderType = GeocoderType.GOOGLE_INTERNAL;
public AdvancedGeoCoder(@NonNull Context context) {
geocoder = new Geocoder(context, new Locale("ru", "RU"));
}
@Nullable
public List<Address> getFromLocation(double lat, double lon) {
addressList.clear();
try {
switch (coderType) {
case GeocoderType.GOOGLE_INTERNAL:
List<Address> fromLocation;
try {
fromLocation = geocoder.getFromLocation(lat, lon, MAX_RESULTS);
addressList.addAll(fromLocation);
} catch (IOException e) {
e.printStackTrace();
}
break;
case GeocoderType.YANDEX:
addressList.add(getLocationFromYandex(lat, lon));
break;
case GeocoderType.GOOGLE_EXTERNAL:
addressList.add(getLocationFromGoogle(lat, lon));
break;
}
} catch (Exception e) {
e.printStackTrace();
}
return addressList.size() == 0 ? null : addressList;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment