如何在@ agm / core中使用谷歌地图的api密钥和客户端ID?

时间:2018-04-05 08:52:02

标签: angularjs google-maps google-maps-api-3 angular-google-maps

我们正在使用agm / core包在Angular应用程序中显示Google地图。 根据@ agm / core可用的文档,它只需要apiKey。

AgmCoreModule.forRoot({ apiKey: 'xxxxxxxxxxxxx' })

但是在我们的应用程序中,我们需要使用Google地图的客户端ID和签名。有没有办法实现这个目标?

1 个答案:

答案 0 :(得分:0)

正如我在AGM的参考文档中所看到的,LazyMapsAPILoaderConfigLiteral

也支持clientId

https://angular-maps.com/api-docs/agm-core/interfaces/LazyMapsAPILoaderConfigLiteral.html#clientId

请注意,初始化接受LazyMapsAPILoaderConfigLiteral对象

static forRoot(lazyMapsAPILoaderConfig?: LazyMapsAPILoaderConfigLiteral): ModuleWithProviders

所以你可以写点像

AgmCoreModule.forRoot({
    clientId: 'gme-xxxxxxxxxxxxx'
});

Google Maps JavaScript API不使用加密密钥。它用于为Web服务请求创建数字签名。它永远不应该被披露,您只能在后端服务器上使用它来创建数字签名,如文档中所述

https://developers.google.com/maps/documentation/geocoding/get-api-key#client-id

请勿在客户端代码中公开加密密钥。

我希望这有帮助!