KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > lamatek > tags > google > beans > GeocoderBean


1 package com.lamatek.tags.google.beans;
2
3 import java.io.Serializable JavaDoc;
4
5 /**
6  * GeocoderBean
7  * @author Tom Cole
8  * @version 0.40
9  *
10  * Default address to lon/lat geocoder. It parses the current information
11  * and passes responsibility to either USAddressGeocoder or IntlAddressGeocoder.
12  *
13  * This class does not perform any actual geocoding itself, rather it
14  * passes to the appropriate geocoder based on country.
15  */

16 public class GeocoderBean implements Geocoder, Serializable JavaDoc {
17
18     private String JavaDoc address = null;
19     private String JavaDoc city = null;
20     private String JavaDoc state = null;
21     private String JavaDoc zip = null;
22     private String JavaDoc country = null;
23     Geocoder coder = null;
24     
25     /**
26      * If developers wish to use other geocoders other than the USAddressGeocoder
27      * and IntlAddressGeocoder, they should override this method to call
28      * the geocoder of their choice.
29      */

30     public boolean geocode() {
31         if (country == null || country.equalsIgnoreCase("US") || country.equalsIgnoreCase("USA")) {
32             coder = new USAddressGeocoder();
33         }
34         else {
35             coder = new IntlAddressGeocoder();
36         }
37         if (address != null)
38             coder.setAddress(address);
39         if (city != null)
40             coder.setCity(city);
41         if (state != null)
42             coder.setState(state);
43         if (zip != null)
44             coder.setZip(zip);
45         if (country != null)
46             coder.setCountry(country);
47         return coder.geocode();
48     }
49     
50     public String JavaDoc getAddress() {
51         return address;
52     }
53     public void setAddress(String JavaDoc address) {
54         this.address = address;
55     }
56     public String JavaDoc getCity() {
57         return city;
58     }
59     public void setCity(String JavaDoc city) {
60         this.city = city;
61     }
62     public String JavaDoc getCountry() {
63         return country;
64     }
65     public void setCountry(String JavaDoc country) {
66         this.country = country;
67     }
68     public String JavaDoc getState() {
69         return state;
70     }
71     public void setState(String JavaDoc state) {
72         this.state = state;
73     }
74     public String JavaDoc getZip() {
75         return zip;
76     }
77     public void setZip(String JavaDoc zip) {
78         this.zip = zip;
79     }
80     public double getLatitude() {
81         if (coder != null)
82             return coder.getLatitude();
83         else
84             return 0.00d;
85     }
86     public double getLongitude() {
87         if (coder != null)
88             return coder.getLongitude();
89         else
90             return 0.00d;
91     }
92     public String JavaDoc getPrecision() {
93         if (coder != null)
94             return coder.getPrecision();
95         else
96             return null;
97     }
98     public String JavaDoc getWarning() {
99         if (coder != null)
100             return coder.getWarning();
101         else
102             return null;
103     }
104 }
105
Popular Tags