Created
December 3, 2019 07:05
-
-
Save dmitriigriazin/248c9226e1a1f1e578414422f19df304 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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