Search in sources :

Example 1 with GeoApiContext

use of com.google.maps.GeoApiContext 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());
    }
}
Also used : GeocodingResult(com.google.maps.model.GeocodingResult) GeoApiContext(com.google.maps.GeoApiContext) Test(org.junit.Test)

Example 2 with GeoApiContext

use of com.google.maps.GeoApiContext 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)2 GeocodingResult (com.google.maps.model.GeocodingResult)2 ApiException (com.google.maps.errors.ApiException)1 IOException (java.io.IOException)1 Test (org.junit.Test)1