1 package com.lamatek.tags.google; 2 3 import java.io.Serializable ; 4 5 import javax.servlet.jsp.tagext.Tag ; 6 import javax.servlet.jsp.tagext.TagSupport ; 7 8 import com.lamatek.tags.google.beans.GeocoderBean; 9 import com.lamatek.tags.google.beans.Ip2GeoCoder; 10 11 20 public class GoogleMapPointTag extends TagSupport implements Serializable { 21 22 String id = null; 23 double latitude = -181.00d; 24 double longitude = -181.00d; 25 String ip = null; 26 String address = null; 27 String city = null; 28 String state = null; 29 String zipcode = null; 30 String country = null; 31 34 public int doEndTag() { 35 if (longitude < -180 || latitude < -90 || longitude > 180 || latitude > 90) { 36 if (geocode()) 37 addTag(); 38 } 39 else { 40 addTag(); 41 } 42 return EVAL_PAGE; 43 } 44 55 public boolean geocode() { 56 if (longitude < -180 || latitude < -90 || longitude > 180 || latitude > 90) { 57 if (ip == null) { 58 GeocoderBean coder = new GeocoderBean(); 59 coder.setAddress(address); 60 coder.setCity(city); 61 coder.setState(state); 62 coder.setCountry(country); 63 coder.setZip(zipcode); 64 if (coder.geocode()) { 65 longitude = coder.getLongitude(); 66 latitude = coder.getLatitude(); 67 return true; 68 } 69 else { 70 return false; 71 } 72 } 73 else { 74 Ip2GeoCoder coder = new Ip2GeoCoder(); 75 coder.setIp(ip); 76 if (coder.geocode()) { 77 longitude = coder.getLongitude(); 78 latitude = coder.getLatitude(); 79 return true; 80 } 81 else { 82 return false; 83 } 84 } 85 } 86 else { 87 return true; 88 } 89 } 90 93 public int doStartTag(){ 94 return SKIP_BODY; 95 } 96 99 private void addTag() { 100 Tag tag = this; 101 while (tag.getParent() != null) { 102 if (tag.getParent() instanceof GoogleMapTag) { 103 ((GoogleMapTag) tag.getParent()).addPoint(this); 104 return; 105 } 106 tag = tag.getParent(); 107 } 108 } 109 114 public void setCenter(boolean center) { 115 if (center) { 116 Tag tag = this; 117 while (tag.getParent() != null) 118 if (tag.getParent() instanceof GoogleMapTag) { 119 ((GoogleMapTag) tag.getParent()).setCenterLatitude(latitude); 120 ((GoogleMapTag) tag.getParent()).setCenterLongitude(longitude); 121 return; 122 } 123 } 124 } 125 131 public void setLatitude(double latitude) { 132 this.latitude = latitude; 133 } 134 140 public void setLongitude(double longitude) { 141 this.longitude = longitude; 142 } 143 148 public void setLatitudeAsString(String value) { 149 try { 150 latitude = Double.parseDouble(value); 151 } 152 catch(NumberFormatException nfe) { 153 nfe.printStackTrace(System.err); 154 } 155 } 156 161 public void setLongitudeAsString(String value) { 162 try { 163 longitude = Double.parseDouble(value); 164 } 165 catch(NumberFormatException nfe) { 166 nfe.printStackTrace(System.err); 167 } 168 } 169 175 public String getAddress() { 176 return address; 177 } 178 183 public void setAddress(String address) { 184 this.address = address; 185 } 186 192 public String getCity() { 193 return city; 194 } 195 201 public void setCity(String city) { 202 this.city = city; 203 } 204 210 public String getCountry() { 211 return country; 212 } 213 218 public void setCountry(String country) { 219 this.country = country; 220 } 221 227 public String getIp() { 228 return ip; 229 } 230 235 public void setIp(String ip) { 236 this.ip = ip; 237 } 238 244 public String getState() { 245 return state; 246 } 247 252 public void setState(String state) { 253 this.state = state; 254 } 255 261 public String getZipcode() { 262 return zipcode; 263 } 264 269 public void setZipcode(String zipcode) { 270 this.zipcode = zipcode; 271 } 272 280 public double getLatitude() { 281 return latitude; 282 } 283 291 public double getLongitude() { 292 return longitude; 293 } 294 299 public String getId() { 300 return id; 301 } 302 308 public void setId(String id) { 309 this.id = id; 310 } 311 } 312 | Popular Tags |