|
public class GeoGoogleTest { |
|
final static String PROXY_SERVER = "myproxy.com"; |
|
final static int PROXY_PORT = 80; |
|
|
|
private static GeoAddressStandardizer createGeoAddressStandardizer() { |
|
final HttpClientParams httpClientParams = new HttpClientParams(); |
|
final HttpClient httpClient = new HttpClient(httpClientParams); |
|
|
|
//enable these 3 lines if you are behind a proxy server. |
|
/* |
|
final HostConfiguration hostConfiguration = new HostConfiguration(); |
|
hostConfiguration.setProxy(PROXY_SERVER, PROXY_PORT); |
|
httpClient.setHostConfiguration(hostConfiguration); |
|
*/ |
|
|
|
GeoAddressStandardizer.setHttpClient(httpClient); |
|
|
|
//this is my key, you must get you own from "http://code.google.com/apis/base/signup.html" and insert it here. |
|
return new GeoAddressStandardizer("ABQXXXXXXXXXXXXXXXXXXX"); |
|
} |
|
|
|
public static void main(final String[] args) throws GeoException { |
|
final String testAddress = "Via Tommaso Campanella, 15b, 00355 Roma, Italy"; |
|
|
|
final GeoAddressStandardizer geoAddressStandardizer = createGeoAddressStandardizer(); |
|
final List<GeoAddress> geoAddresses = geoAddressStandardizer.standardizeToGeoAddresses(testAddress); |
|
|
|
for (final GeoAddress geoAddress : geoAddresses) { |
|
System.out.println(geoAddress.getAddressLine()); |
|
} |
|
|
|
final String addressLine1 = geoAddressStandardizer.standardize(testAddress, new XmlMappingFunctor<String>() { |
|
@Override |
|
public String execute(final String xml) { |
|
try { |
|
// parse the xml string into a document object |
|
final Document doc = XmlUtils.parse(xml); |
|
|
|
System.out.println(xml); |
|
|
|
// use XPath to select an value from the document |
|
return XmlUtils.selectValue(doc, "//ThoroughfareName"); |
|
} catch (final Exception e) { |
|
System.out.println(e.getMessage()); |
|
} |
|
|
|
return null; |
|
} |
|
}); |
|
|
|
System.out.println("Output ==> " + addressLine1); |
|
} |
|
|
|
} |
No comments:
Post a Comment