Geocoding

The Geocoding service provides methods related to converting street addresses to or from longitude and latitude coordinates.

Geocoding

Geocoding allows you to retrieve longitude and latitude coordinates for a given address. Geocoding is done by making a call to the TrimbleMaps.Geocoder.geocode method. The geocode method takes an object with four possible parameters.

Input Parameters

Parameter NameDescription
addressObject containing properties for the address. Properties addr, city, state, zip, region.
listSizeNumber of results to be returned.
successFunction called when the geocoding completes.
failureFunction called when the geocoding fails.

Example

TrimbleMaps.Geocoder.geocode({
  address: {
    addr: "1 Independence Way",
    city: "Princeton",
    state: "NJ",
    zip: "08540",
    region: TrimbleMaps.Common.Region.NA
  },
  listSize: 1,
  success: function(response) {
    console.log(response);
  },
  failure: function(response) {
    console.log(response);
  }
});

The response from the geocode method is an array of JavaScript objects that contains the longitude and latitude coordinates for the address if the address could be resolved. In addition, the object contains a normalized address object as well as an array of error/warning messages.

Reverse Geocoding

Reverse Geocoding allows you to retrieve the nearest address for given longitude and latitude coordinates using the TrimbleMaps.Geocoder.reverseGeocode method.

Input Parameters

Parameter NameDescription
lonLatLongitude/Latitude object to be reverse geocoded.
regionEnumeration for the region.
successFunction called when the reverse geocoding completes.
failureFunction called when the reverse geocoding fails.

Example

TrimbleMaps.Geocoder.reverseGeocode({
  lonLat: new TrimbleMaps.LngLat(-122.31693, 47.60784),
  region: TrimbleMaps.Common.Region.NA,
  success: function(response) {
    console.log(response);
  },
  failure: function(response) {
    console.log(response);
  }
});