我们使用 agm/core 包在 Angular 应用程序中显示 Google 地图。
根据 @agm/core 可用的文档,它仅需要 apiKey。
AgmCoreModule.forRoot({
apiKey: 'xxxxxxxxxxxxx'
})
然而,在我们的应用程序中,我们需要使用 Google 地图的客户端 ID 和签名。有办法实现这一点吗?
正如我在 AGM 的参考文档中看到的,clientId 也受支持LazyMapsAPILoaderConfigLiteral
https://angular-maps.com/api-docs/agm-core/interfaces/LazyMapsAPILoaderConfigLiteral.html#clientId https://angular-maps.com/api-docs/agm-core/interfaces/LazyMapsAPILoaderConfigLiteral.html#clientId
请注意,初始化接受LazyMapsAPILoaderConfigLiteral
object
static forRoot(lazyMapsAPILoaderConfig?: LazyMapsAPILoaderConfigLiteral): ModuleWithProviders
所以你可以写类似的东西
AgmCoreModule.forRoot({
clientId: 'gme-xxxxxxxxxxxxx'
});
Google 地图 JavaScript API 不使用加密密钥。它用于为 Web 服务请求创建数字签名。它永远不应该被披露,您只能在后端服务器上使用它来创建数字签名,如文档中所述
https://developers.google.com/maps/documentation/geocoding/get-api-key#client-id https://developers.google.com/maps/documentation/geocoding/get-api-key#client-id
确保不要在客户端代码中公开加密密钥。
我希望这有帮助!
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)