/* https://docs.nestjs.com/providers#services */ import { Injectable } from '@nestjs/common'; import * as NodeGeocoder from 'node-geocoder'; import { ListsService } from 'src/backoffice/lists/lists.service'; @Injectable() export class GoogleService { constructor( private readonly listsService: ListsService) {} async getGeocoder(address: string, addressNumber: string, neighborhood: string, city: string, state: string) { const stateName = await this.listsService.GetStates(state); const options = { provider: 'google', // Optional depending on the providers // fetch: customFetchImplementation, apiKey: 'AIzaSyBc0DiFwbS0yOJCuMi1KGwbc7_d1p8HyxQ', // for Mapquest, OpenCage, Google Premier formatter: null // 'gpx', 'string', ... }; const geocoder = NodeGeocoder(options); const completeAddress = addressNumber + ' ' + address + ' ' + neighborhood + ' ' + city + ' ' + stateName; // Using callback const res = await geocoder.geocode(completeAddress); return res; } }