src/identifier.js
// placeholder method for utlizing a geolocation API
placeholder method for utlizing a geolocation API
placeholder method for utlizing a geolocation API
async parseAddressToCoordinates(address) {
    if (!address || !this.config.googleMapsApiKey || !module) {
      return {};
    }
    if (!this._googleMapsClient) {
      this._googleMapsClient = require("@google/maps").createClient({
        key: this.config.googleMapsApiKey,
        Promise,
      });
    }
    const payload = {};
    const { json } = await this._googleMapsClient
      .geocode({ address })
      .asPromise();
    if (json.results && json.results[0]) {
      const [place] = json.results;
      if (place.geometry && place.geometry.location) {
        payload.latitude = place.geometry.location.lat;
        payload.longitude = place.geometry.location.lng;
      }
      if (place.address_components instanceof Array) {
        const subpremise = place.address_components.find(
          ac =>
            ac && ac.types instanceof Array && ac.types.includes("subpremise"),
        );
        if (subpremise) {
          payload.unitNumber = subpremise.short_name;
        }
      }
    }
    return payload;
  }
async parseAddressToCoordinates ( address ) { if ( ! address || ! this . config . googleMapsApiKey || ! module ) { return { } ; } if ( ! this . _googleMapsClient ) { this . _googleMapsClient = require ( "@google/maps" ) . createClient ( { key : this . config . googleMapsApiKey , Promise , } ) ; } const payload = { } ; const { json } = await this . _googleMapsClient . geocode ( { address } ) . asPromise ( ) ; if ( json . results && json . results [ 0 ] ) { const [ place ] = json . results ; if ( place . geometry && place . geometry . location ) { payload . latitude = place . geometry . location . lat ; payload . longitude = place . geometry . location . lng ; } if ( place . address_components instanceof Array ) { const subpremise = place . address_components . find ( ac => ac && ac . types instanceof Array && ac . types . includes ( "subpremise" ) , ) ; if ( subpremise ) { payload . unitNumber = subpremise . short_name ; } } } return payload ; }
placeholder method for utlizing a geolocation API
placeholder method for utlizing a geolocation API
// make sure we have an address and a google maps config // also the @google/maps package requires running in node //    sooo this won't work in a browser //    https://github.com/googlemaps/google-maps-services-js#attention // eslint-disable-next-line global-require // make sure we have a valid result from Google // pull out the lat and lng // figure out the unit