【发布时间】:2019-03-14 11:17:58
【问题描述】:
使用GeoApiContext和HttpClient的两个策略中使用java的反向地理编码的java代码。
公共类 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;
}
}
【问题讨论】:
-
有问题吗?