Skip to main content

Geocoding

Geocoding allows you to retrieve longitude and latitude coordinates for a given address. To geocode an address:

Retrieve the geocoding module:

const TrimbleMapsGeocoding = NativeModules.TrimbleMapsGeocoding;

Submit an address and retrieve geocoding results.

useEffect(() => {
  const searchTerm = "1 Independence Way Princeton NJ 08540";
  // callback for results
  const geocodeCallback = (error, results) => {
    if (error) {
      console.log(error);
    } else {
      const firstResult = JSON.parse(results[0]);
      console.log(results[0]);
      const lat = parseFloat(firstResult.Coords.Lat);
      const lon = parseFloat(firstResult.Coords.Lon);
      moveCameraAndZoom(lat, lon, 13);
    }
  };

  // create geocoding request
  if (Platform.OS === "ios") {
    TrimbleMapsGeocoding.createGeocodingParams(searchTerm);
    TrimbleMapsGeocoding.geocode(geocodeCallback);
  } else if (Platform.OS === "android") {
    TrimbleMapsMapView.getMapAsync(() => {
      TrimbleMapsGeocoding.createGeocodingBuilder();
      TrimbleMapsGeocoding.query(searchTerm);
      TrimbleMapsGeocoding.buildGeocoding();
      TrimbleMapsGeocoding.geocode(geocodeCallback);
    });
  }
}, [mapLoaded]);
Last updated February 6, 2024.