commit
This commit is contained in:
20
src/google/google.module.ts
Normal file
20
src/google/google.module.ts
Normal 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 {
|
||||
|
||||
|
||||
}
|
||||
36
src/google/google.service.ts
Normal file
36
src/google/google.service.ts
Normal 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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user