/[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 2300 by torben, Sun Feb 15 11:00:48 2015 UTC revision 2301 by torben, Sun Feb 15 16:09:11 2015 UTC
# Line 1  Line 1 
1  package dk.daoas.daoadresseservice;  package dk.daoas.daoadresseservice;
2    
3  import java.io.IOException;  import java.io.IOException;
4    import java.net.URLEncoder;
5  import java.util.List;  import java.util.List;
6    
7  import com.google.code.geocoder.Geocoder;  import com.google.code.geocoder.Geocoder;
# Line 10  import com.google.code.geocoder.model.Ge Line 11  import com.google.code.geocoder.model.Ge
11  import com.google.code.geocoder.model.GeocoderRequest;  import com.google.code.geocoder.model.GeocoderRequest;
12  import com.google.code.geocoder.model.GeocoderResult;  import com.google.code.geocoder.model.GeocoderResult;
13  import com.google.code.geocoder.model.GeocoderStatus;  import com.google.code.geocoder.model.GeocoderStatus;
14    import com.google.gson.Gson;
15    
16    import dk.daoas.daoadresseservice.beans.OSMAddress;
17    
18  public class GeocodeHelper {  public class GeocodeHelper {
19                    
20                    
21            
22    
23    
24          public static void main(String[] args) throws IOException {                      public static void main(String[] args) throws IOException {            
25                  System.out.println(  GeocodeHelper.googleHelper(2800, "Chr. Xs Alle") );                  //System.out.println(  GeocodeHelper.googleHelper(2800, "Chr. Xs Alle") );
26                    System.out.println(  GeocodeHelper.openstreetmapHelper(2800, "Chr. Xs Alle") );
27                    System.out.println(  GeocodeHelper.openstreetmapHelper(8700, "Enebaervej") );
28            }
29            
30            public static String openstreetmapHelper(int postnr, String vejnavn) {
31                    
32                    try {
33                                    
34                            String encVej = URLEncoder.encode(vejnavn, "UTF-8");
35                            
36                            String url = "http://nominatim.openstreetmap.org/search?country=DK&street=" + encVej + "&postalcode=" + postnr + "&format=json&addressdetails=1";
37                            //String url = "http://nominatim.openstreetmap.org/search?country=DK&street=" + encVej + "&format=json&addressdetails=1";
38                            //System.out.println (url);
39                            
40                            String json = HttpUtil.getContentString(url, 1000);
41                            //System.out.println(json);
42                            
43                            Gson gson = new Gson();
44                            OSMAddress adrList[] = gson.fromJson(json, OSMAddress[].class);
45                            
46                            //System.out.println("Count: " + adrList.length);
47                            if (adrList.length != 1)
48                                    return null;
49                                    
50                            if (adrList[0].address != null) {
51                                    return adrList[0].address.road;
52                            }
53    
54                            
55                    } catch (Exception e) {
56                            System.out.println( "Error: " + e.getMessage() );
57                    }                                                              
58                    return null;
59          }          }
60                    
61            
62            
63          public static String googleHelper(int postnr, String vejnavn) {          public static String googleHelper(int postnr, String vejnavn) {
64                  try {                  try {
65                          //Todo: Load api key from context config                          //Todo: Load api key from context config

Legend:
Removed from v.2300  
changed lines
  Added in v.2301

  ViewVC Help
Powered by ViewVC 1.1.20