鸟巢图
A 类 网点JS 配置一个 谷歌地图服务 通过依赖性注射的客户端。 它包括地点细节、倒向地理编码、地缘定位、高地和时区等方便方法,可直接访问基本的客户端.
兼容性
在共同JS和无害环境管理应用中支持NestJS 11和12。 已出版的JavaScript是带有类型Script声明的通用JS;ESM应用程序可以使用命名的导入. NestJS 12要求节点20.19+(节点22.12+;节点24被推荐.
安装
npm install @eddaic/nestjs-google-maps @nestjs/config
使用量
初始化
import { GoogleMapsModule } from '@eddaic/nestjs-google-maps';
import { Module } from '@nestjs/common';
import { ConfigModule, ConfigService } from '@nestjs/config';
@Module({
imports: [
ConfigModule.forRoot({ isGlobal: true }),
GoogleMapsModule.registerAsync({
inject: [ConfigService],
useFactory: (config: ConfigService) => ({
params: { key: config.getOrThrow<string>('GOOGLE_API_KEY') },
}),
}),
],
})
export class AppModule {}
通话
在您的申请中注册此服务 providers。 。 。 .
import { GoogleMapsService } from '@eddaic/nestjs-google-maps';
import { Injectable } from '@nestjs/common';
@Injectable()
export class AppService {
constructor(private readonly maps: GoogleMapsService) {}
async lookup(place_id: string, points: { lat: number; lng: number }[]) {
// Some convenience methods are included
const placeDetails = await this.maps.placeDetails({ place_id });
// Otherwise can access the client directly for full set of APIs
const params = { ...this.maps.params, points };
const response = await this.maps.client.nearestRoads({ params });
return { placeDetails, roads: response.data };
}
}