angular - How to fix Google Maps Platform rejected your request. Invalid request. Unexpected parameter 'amp%3Bkey'
问题描述
angular error
Google Maps Platform rejected your request. Invalid request. Unexpected parameter 'amp%3Bkey'.
in console
GET https://www.google.com/maps/embed/v1/place?q=19.499201,77.656332&key=APIKEY 400
HTML code
<iframe width="100%" height="150" frameborder="0" style="border:0" [src]="location(details)"></iframe>
TS code
location(details:any){
let location = `https://www.google.com/maps/embed/v1/place?q=${details.longitude},${details.latitude}&key=<apiKey>`;
return this.sanitizer.bypassSecurityTrustResourceUrl(location);
}
I am facing the issue with
bypassSecurityTrustResourceUrl function which converts the string ',' comma to '%3B'
.
解决方案
在上面的示例中,我将 iframe 源地址与 ResourceUrl sanitizer 一起使用,这导致字符串 ',' 以某种方式转换为 '%3B'。最后哪个不起作用。所以我使用了从 ts 文件中清理 HTML 的替代方法,如下所示。
HTML
<div class="map-box" [innerHtml]="Location(Details) | safe: 'html'">
TS
Location(details:any){
let locationIframe = `<iframe width="100%" height="150" frameborder="0" style="border:0" src="https://www.google.com/maps/embed/v1/place?q=${details.longitude},${details.latitude}&key=${this.gmapApiKey}" > </iframe>`;
return locationIframe;
}
管道->安全:'html'
return this.sanitizer.bypassSecurityTrustHtml(value);
推荐阅读
- gremlin-server - 通过 BulkLoaderVertexProgram 将非常大的图形加载到 gremlin 服务器中
- java - 如何在 Clojure 中使用 defrecord 来扩展 Java 类?
- mysql - FIND_IN_SET 等效于带有 IF 条件的 SQL Server
- django - NoReverseMatch at /posts/list/ 未找到“post_detail”的反向。“post_detail”不是有效的视图函数或模式名称
- list-comprehension - 多个列表中每个位置的最大值
- php - 在 CakePHP 中,如何从图像数组中获取客户端文件名?
- python - 如何在 Notepad++ 中为使用 Python 保存的 JSON 正确解析 JSON?
- data-visualization - Oracle 用于数据可视化的各种选项/工具
- javascript - 当一个proto obj由defineProperty定义时,具有相同属性的hasOwnProperty会出错,为什么?
- python - 如何构建神经网络模型以在 python 中对数据进行分类