Search in sources :

Example 1 with LatLng

use of com.google.code.geocoder.model.LatLng in project camel by apache.

the class GeoCoderProducer method process.

public void process(Exchange exchange) throws Exception {
    // header take precedence
    String address = exchange.getIn().getHeader(GeoCoderConstants.ADDRESS, String.class);
    if (address == null) {
        address = endpoint.getAddress();
    }
    String latlng = exchange.getIn().getHeader(GeoCoderConstants.LATLNG, String.class);
    if (latlng == null) {
        latlng = endpoint.getLatlng();
    }
    if (latlng != null) {
        GeocoderRequest req = new GeocoderRequest();
        req.setLanguage(endpoint.getLanguage());
        String lat = ObjectHelper.before(latlng, ",");
        String lng = ObjectHelper.after(latlng, ",");
        req.setLocation(new LatLng(lat, lng));
        LOG.debug("Geocode for lat/lng {}", latlng);
        GeocodeResponse res = geocoder.geocode(req);
        LOG.debug("Geocode response {}", res);
        if (res != null) {
            extractGeoResult(res, exchange);
        }
    } else if (address != null) {
        // is it current address
        if ("current".equals(address)) {
            processCurrentLocation(exchange);
        } else {
            LOG.debug("Geocode for address {}", address);
            GeocoderRequest req = new GeocoderRequest(address, endpoint.getLanguage());
            GeocodeResponse res = geocoder.geocode(req);
            LOG.debug("Geocode response {}", res);
            if (res != null) {
                extractGeoResult(res, exchange);
            }
        }
    }
}
Also used : GeocodeResponse(com.google.code.geocoder.model.GeocodeResponse) LatLng(com.google.code.geocoder.model.LatLng) GeocoderRequest(com.google.code.geocoder.model.GeocoderRequest)

Example 2 with LatLng

use of com.google.code.geocoder.model.LatLng in project camel by apache.

the class GeoCoderProxyTest method testGeoCoder.

@Test
public void testGeoCoder() throws Exception {
    GeoCoderEndpoint endpoint = context.getEndpoint("geocoder:address:current?headersOnly=true&proxyHost=localhost&proxyPort=3128&proxyAuthMethod=Basic&proxyAuthUsername=proxy&proxyAuthPassword=proxy", GeoCoderEndpoint.class);
    Geocoder geocoder = endpoint.createGeocoder();
    GeocoderRequest req = new GeocoderRequest();
    req.setLocation(new LatLng("45.4643", "9.1895"));
    GeocodeResponse res = geocoder.geocode(req);
    log.info("Response {} ", res);
}
Also used : GeocodeResponse(com.google.code.geocoder.model.GeocodeResponse) LatLng(com.google.code.geocoder.model.LatLng) Geocoder(com.google.code.geocoder.Geocoder) GeocoderRequest(com.google.code.geocoder.model.GeocoderRequest) Test(org.junit.Test)

Aggregations

GeocodeResponse (com.google.code.geocoder.model.GeocodeResponse)2 GeocoderRequest (com.google.code.geocoder.model.GeocoderRequest)2 LatLng (com.google.code.geocoder.model.LatLng)2 Geocoder (com.google.code.geocoder.Geocoder)1 Test (org.junit.Test)1