Search in sources :

Example 1 with ApiException

use of com.google.maps.errors.ApiException 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;
}
Also used : GeocodingResult(com.google.maps.model.GeocodingResult) IOException(java.io.IOException) GeoApiContext(com.google.maps.GeoApiContext) ApiException(com.google.maps.errors.ApiException)

Aggregations

GeoApiContext (com.google.maps.GeoApiContext)1 ApiException (com.google.maps.errors.ApiException)1 GeocodingResult (com.google.maps.model.GeocodingResult)1 IOException (java.io.IOException)1