/[projects]/dao/DaoAdresseService/src/dk/daoas/daoadresseservice/GeocodeHelper.java
ViewVC logotype

Diff of /dao/DaoAdresseService/src/dk/daoas/daoadresseservice/GeocodeHelper.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2348 by torben, Wed Feb 18 07:45:28 2015 UTC revision 2349 by torben, Mon Feb 23 15:02:48 2015 UTC
# Line 13  import com.google.code.geocoder.model.Ge Line 13  import com.google.code.geocoder.model.Ge
13  import com.google.code.geocoder.model.GeocoderStatus;  import com.google.code.geocoder.model.GeocoderStatus;
14  import com.google.gson.Gson;  import com.google.gson.Gson;
15    
16    import dk.daoas.daoadresseservice.admin.ServiceConfig;
17  import dk.daoas.daoadresseservice.beans.OSMAddress;  import dk.daoas.daoadresseservice.beans.OSMAddress;
18  import dk.daoas.daoadresseservice.util.HttpUtil;  import dk.daoas.daoadresseservice.util.HttpUtil;
19    
20  public class GeocodeHelper {  public class GeocodeHelper {
21                            
           
           
22    
23    
24          public static void main(String[] args) throws IOException {          public static void main(String[] args) throws IOException {
25                    ServiceConfig conf = new ServiceConfig();
26                    
27                  int post = 8700;                  int post = 8700;
28                  String vej = "Enebarvej";                  String vej = "Enebarvej";
29                                    
30                  long start1 = System.currentTimeMillis();                  long start1 = System.currentTimeMillis();
31                  System.out.println( "Google:" +  GeocodeHelper.googleHelper(post, vej) );                                System.out.println( "Google:" +  GeocodeHelper.googleHelper(conf, post, vej) );        
32                  long stop1 = System.currentTimeMillis();                  long stop1 = System.currentTimeMillis();
33                                    
34                  long start2 = System.currentTimeMillis();                  long start2 = System.currentTimeMillis();
# Line 71  public class GeocodeHelper { Line 72  public class GeocodeHelper {
72                    
73                    
74                    
75          public static String googleHelper(int postnr, String vejnavn) {          public static String googleHelper(ServiceConfig conf, int postnr, String vejnavn) {
76                  try {                  try {
77                          //Todo: Load api key from context config                          //Todo: Load api key from context config
78                          final Geocoder geocoder = new Geocoder();                          final Geocoder geocoder;
79                            if ( conf.googleApiKey != null ) {
80                                    geocoder = new Geocoder(conf.googleApiUser, conf.googleApiKey); //Throws InvalidKeyException
81                            } else {
82                                    geocoder = new Geocoder();
83                            }
84                            
85                                                    
86                          String search = vejnavn + ", " + postnr + ", Denmark";                          String search = vejnavn + ", " + postnr + ", Denmark";
87                          GeocoderRequest geocoderRequest = new GeocoderRequestBuilder().setAddress(search).setLanguage("en").getGeocoderRequest();                          GeocoderRequest geocoderRequest = new GeocoderRequestBuilder().setAddress(search).setLanguage("en").getGeocoderRequest();
# Line 103  public class GeocodeHelper { Line 110  public class GeocodeHelper {
110                                  }                                  }
111                          }                          }
112                                                    
113                  } catch (IOException e) {                  } catch (Exception e) {
114                          System.out.println( "GoogleError: " + e.getMessage() );                          System.out.println( "GoogleError: " + e.getMessage() );
115                  }                  }
116                  return null;                  return null;

Legend:
Removed from v.2348  
changed lines
  Added in v.2349

  ViewVC Help
Powered by ViewVC 1.1.20