Configuring

Provided in the Spectrum Global Geocoding SDK is a configuration file called geocodingPreferences.xml, located in XXXX after deploying the SDK. You can use this if you wish to set system wide preferences.

<geocodePreferences> </geocodePreferences>

The main entry point for the Spectrum Global Geocoding SDK is described by the GeocodingAPI interface, which allows access to the basic functionaity for geocoding and interactive :

  • geocode — geocodes a single address. The address must contain a valid ISO 3166-1 Alpha-3 Country code or country name. Any other address information can go in the MainAddressLine field (for example “350 Jordan Rd, Troy NY 12180”); or be divided between MainAddressLine and AddressLastLine. For example: MainAddressLine = ““350 Jordan Rd”, AddressLastLine = ”Troy NY 12180”). The address last line fields can also be entered individually in the AreaName<1-4> and PostCode fields.
  • geocodeMultiple — allows a batch of addresses to be geocoded at one time. Each address must contain a valid ISO 3166-1 Alpha-3 Country code.
  • reverseGeocode — returns the closest candidate to the input location. Country input is optional for reverse geocode, but it may improve performance if the country is specified.
  • reverseGeocodeMultiple — allows reverse geocoding of a batch of locations.
  • suggest — (Part of the InteractiveGeocodingAPI) Provides the address completion for the given string input. The search string can be entered as part of mainAddressLine or street, with ISO country being an optional field. If country is provided, search will be performed for that country, or else will be performed for all the data configured.
  • keyLookup — returns geocoded candidates when given a unique key. The key is unique to that address.
  • keyLookupMultiple — returns geocoded candidates when given a unique key in batch.
  • getCapabilities — returns a description of the API capabilities for each supported country.
  • getConfiguredDictionaries — lists the source geocoding datasets and their defined priority for each supported country.
    Note: Geocoding datasets have been referred to as "dictionaries" in the past.

Getting Started

The main entry point for the Spectrum Global Geocoding SDK is described by the GeocodingAPIinterface, which is implemented by the Geocoder class. In order to use the Spectrum Global Geocoding SDK once installation is complete, refer to the example below for the sequence of calls to add to your Java program:

GeocodingAPI geocoder = new Geocoder();
Address address = new GeocodeAddress();
address.setMainAddress(“1600 Pennsylvania Ave NW, Washington DC”);
address.setCountry(“USA”);
GeocoderPreferences preferences = new GeocoderPreferences();
Response response = geocoder.geocode(GeocodeType.ADDRESS, address,
      preferences);

If you want to configure the Spectrum Global Geocoding SDK geocoding datasets using Java, there is a second constructor for the Geocoder class, which takes a map of country names to geocoding dataset properties.

Next, make a Map of ISO-3166 Alpha-3 country codes to those Properties objects, and pass them in to the geocoder. For example,

// setting up Germany “DEU”
Properties properties = new Properties();
properties.put("DICTIONARY_COUNT","2");
properties.put("DICTIONARY_PATH1","//localdata/DEU/address_dictionary/AP");
properties.put("DICTIONARY_PATH2","//localdata/DEU/address_dictionary/Standard");
Map<String, Properties> map = new HashMap<String,Properties>();
map.put("DEU", properties);
// now adding Denmark
properties = new Properties();properties.put("DICTIONARY_COUNT","1");
properties.put("DICTIONARY_PATH1","//localdata/DNK/address_dictionary");
map.put(“DNK”, properties);
JavaDataManagerSettingsMapper mapper = new 
     JavaDataManagerSettingsMapper();
mapper.setCountryPropMap(map);
Geocoder engine = new Geocoder(mapper);//engine is now initialized and ready for use

Note that the geocoding dataset initialization happens only with the first instance of a Geocoder created, so you should only have one Geocoder in a JVM instance.