--- dao/DaoAdresseService/src/dk/daoas/daoadresseservice/GeocodeHelper.java 2015/02/23 15:01:15 2348 +++ dao/DaoAdresseService/src/dk/daoas/daoadresseservice/GeocodeHelper.java 2015/02/23 15:02:48 2349 @@ -13,21 +13,22 @@ import com.google.code.geocoder.model.GeocoderStatus; import com.google.gson.Gson; +import dk.daoas.daoadresseservice.admin.ServiceConfig; import dk.daoas.daoadresseservice.beans.OSMAddress; import dk.daoas.daoadresseservice.util.HttpUtil; public class GeocodeHelper { - - - + public static void main(String[] args) throws IOException { + ServiceConfig conf = new ServiceConfig(); + int post = 8700; String vej = "Enebarvej"; long start1 = System.currentTimeMillis(); - System.out.println( "Google:" + GeocodeHelper.googleHelper(post, vej) ); + System.out.println( "Google:" + GeocodeHelper.googleHelper(conf, post, vej) ); long stop1 = System.currentTimeMillis(); long start2 = System.currentTimeMillis(); @@ -71,10 +72,16 @@ - public static String googleHelper(int postnr, String vejnavn) { + public static String googleHelper(ServiceConfig conf, int postnr, String vejnavn) { try { //Todo: Load api key from context config - final Geocoder geocoder = new Geocoder(); + final Geocoder geocoder; + if ( conf.googleApiKey != null ) { + geocoder = new Geocoder(conf.googleApiUser, conf.googleApiKey); //Throws InvalidKeyException + } else { + geocoder = new Geocoder(); + } + String search = vejnavn + ", " + postnr + ", Denmark"; GeocoderRequest geocoderRequest = new GeocoderRequestBuilder().setAddress(search).setLanguage("en").getGeocoderRequest(); @@ -103,7 +110,7 @@ } } - } catch (IOException e) { + } catch (Exception e) { System.out.println( "GoogleError: " + e.getMessage() ); } return null;