This commit is contained in:
Felipe Batista
2025-01-27 17:44:27 -03:00
commit 47e7f75720
238 changed files with 36425 additions and 0 deletions

View File

@@ -0,0 +1,20 @@
import { ListsService } from 'src/backoffice/lists/lists.service';
import { GoogleService } from './google.service';
/*
https://docs.nestjs.com/modules
*/
import { Module } from '@nestjs/common';
@Module({
imports: [],
controllers: [],
providers: [
GoogleService,
ListsService],
})
export class GoogleModule {
}

View File

@@ -0,0 +1,36 @@
/*
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;
}
}