{
if (response != null
&& response.getStatus() != null
&& response.getStatus().equals("OK"))
{
PostalGeolocation location = new PostalGeolocation();
List<GoogleGeocodeResponse.Results.Address_Components> addressComponents;
for (GoogleGeocodeResponse.Results result : response.getResults())
{
addressComponents = result.getAddress_components();
for (GoogleGeocodeResponse.Results.Address_Components addressComponent : addressComponents)
{
for (String str : addressComponent.getTypes())
{
if (str.equalsIgnoreCase("locality"))
{
location.setCity(addressComponent.getShort_name());
}
else if (str.equalsIgnoreCase("administrative_area_level_1"))
{
location.setState(addressComponent.getShort_name());
}
else if (str.equalsIgnoreCase("postal_code"))
{
location.setPostalCode(addressComponent.getShort_name());
}
}
}
location.setLatitude(result.getGeometry().getLocation().getLat());
location.setLongitude(result.getGeometry().getLocation().getLng());
}
return location;
}