use of com.google.maps.model.GeocodingResult in project cas by apereo.
the class GoogleMapsGeoLocationService method locate.
@Override
public GeoLocationResponse locate(final Double latitude, final Double longitude) {
if (latitude == null || longitude == null) {
LOGGER.debug("latitude/longitude must not be null in order for geolocation to proceed");
return null;
}
final GeoLocationResponse r = new GeoLocationResponse();
r.setLatitude(latitude);
r.setLongitude(longitude);
final LatLng latlng = new LatLng(latitude, longitude);
try {
final GeocodingResult[] results = GeocodingApi.reverseGeocode(this.context, latlng).await();
if (results != null && results.length > 0) {
Arrays.stream(results).map(result -> result.formattedAddress).forEach(r::addAddress);
return r;
}
} catch (final Exception e) {
LOGGER.error(e.getMessage(), e);
}
return r;
}
use of com.google.maps.model.GeocodingResult in project amos-ss17-alexa by c-i-ber.
the class LocationTest method geoCodingTest.
@Test
public void geoCodingTest() throws InterruptedException, ApiException, IOException {
GeoApiContext context = new GeoApiContext().setApiKey("AIzaSyB-N97d_umXxnlkzBSP27do83hYgo1hEeo");
GeocodingResult[] results = GeocodingApi.geocode(context, "Wölkernstraße 11 90459 Nürnberg").await();
for (GeocodingResult result : results) {
System.out.println(result.geometry.location.toString());
}
}
use of com.google.maps.model.GeocodingResult in project amos-ss17-alexa by c-i-ber.
the class GeoCoder method getLatLng.
/**
* converts address to geo code to perform place search
* @param address device address
* @return LatLng of device
*/
public static LatLng getLatLng(Address address) {
GeoApiContext context = new GeoApiContext().setApiKey(GOOGLE_MAP_API_KEY);
GeocodingResult[] results = null;
try {
//log.info("Address: " + encoded);
results = GeocodingApi.geocode(context, "Nürnberg 90459 Bulmannstraße 44").await();
} catch (ApiException | InterruptedException | IOException e) {
e.printStackTrace();
}
assert results != null : "GeoCoder could not convert address to lat lang!";
return results[0].geometry.location;
}
Aggregations