JavaScript - Location Widget

Site Search offers a native JavaScript search-location widget for your custom search page.

The SearchstaxLocationWidget provides a location search input with location-based search functionality.

Usage

function locationDecodeFunction(term: string): Promise<ISearchstaxLocation>{
        return new Promise((resolve) => {
          // make a request to geocoding API to retrieve lat, lon and address and then resolve promise
      resolve({
                  address:'Address',
                  lat: lat,
                  lon: lon,
                  error: false
                });
        });
  }

  function locationDecodeCoordinatesToAddress(lat, lon): Promise<ISearchstaxLocation>{
      return new Promise((resolve) => {
        // make a request to geocoding API to convert lat, lon to address and then resolve promise
      resolve({
                  address:'Address',
                  lat: lat,
                  lon: lon,
                  error: false
                });
      });
    }
 searchstax.addSearchLocationWidget("searchstax-location-container", {
  hooks: {
    locationDecode: locationDecodeFunction,
    locationDecodeCoordinatesToAddress: locationDecodeCoordinatesToAddress
    },
});

Props

  • hooks.locationDecode – A callback function that fires after location input blurs. It decodes a string to coordinates.
  • hooks.locationDecodeCoordinatesToAddress – A callback function to override location decoding.
  • templates – See the example at searchstax-ux-js.

Example

See the full example at searchstax-ux-js.

Articles in this section