Java-код обратного геокодирования с использованием Java в двух стратегических системах с использованием GeoApiContext и HttpClient.
открытый класс ReverseGeoCoderUtil {
/**
* Reverse Geocoding and returns formated Address .
* eg:getFormatedAdress(40.714224, -73.961452);
*
* @param latitude latitude value
* @param longitude longitude value
* @param googleApiKey
* @throws Exception if a reverse geocoding error occurred
* @return formated Address
*/
public static String getFormatedAdress(double latitude, double longitude, String googleApiKey) throws Exception
{
GeoApiContext context = new GeoApiContext.Builder().apiKey(googleApiKey).build();
String name = "(Unknown)";
try {
GeocodingResult[] results = GeocodingApi.reverseGeocode(context, new LatLng(latitude, longitude)).await();
for (GeocodingResult result : results) {
return result.formattedAddress;
}
} catch (Exception e) {
throw new Exception("Error on Reverse Geocoding");
}
return name;
}
}