gpt4 book ai didi

angular - 引用错误 : google is not defined on using PrimeNG GMap

转载 作者:太空狗 更新时间:2023-10-29 17:43:21 25 4
gpt4 key购买 nike

我在我的项目中使用 PrimeNg GMap,但出现错误“ReferenceError: google is not defined”我正在点击此链接获取文档 https://www.primefaces.org/primeng/#/gmap .请告诉我如何为 GMap 添加 api key 。 error image

我的组件

import {GMapModule} from 'primeng/primeng';

@Component({
selector: 'mycomponent',
templateUrl: './mycomponent.component.html',

[})
export c][1]lass MyComponent implements OnInit {

options: any;

overlays: any[];

ngOnInit() {
this.options = {
center: {lat: 36.890257, lng: 30.707417},
zoom: 12
};

this.overlays = [
new google.maps.Marker({position: {lat: 36.879466, lng: 30.667648}, title:"Konyaalti"}),
new google.maps.Marker({position: {lat: 36.883707, lng: 30.689216}, title:"Ataturk Park"}),
new google.maps.Marker({position: {lat: 36.885233, lng: 30.702323}, title:"Oldtown"}),
new google.maps.Polygon({paths: [
{lat: 36.9177, lng: 30.7854},{lat: 36.8851, lng: 30.7802},{lat: 36.8829, lng: 30.8111},{lat: 36.9177, lng: 30.8159}
], strokeOpacity: 0.5, strokeWeight: 1,fillColor: '#1976D2', fillOpacity: 0.35
}),
new google.maps.Circle({center: {lat: 36.90707, lng: 30.56533}, fillColor: '#1976D2', fillOpacity: 0.35, strokeWeight: 1, radius: 1500}),
new google.maps.Polyline({path: [{lat: 36.86149, lng: 30.63743},{lat: 36.86341, lng: 30.72463}], geodesic: true, strokeColor: '#FF0000', strokeOpacity: 0.5, strokeWeight: 2})
];
}

HTML代码

<p-gmap [options]="options" [overlays]="overlays" [style]="{'width':'100%','height':'320px'}" ></p-gmap>

最佳答案

PrimeNG 文档在这方面不是很好,不过查看 GitHub 存储库会有所帮助。尝试将 google API 脚本添加到 Index.html:

<script src="https://maps.googleapis.com/maps/api/js?key=YOUR_KEY_GOES_HERE"></script>

请注意,您需要添加自己的 API key 。

另请注意,我删除了延迟异步,因为在直接加载页面时这会导致错误。

关于angular - 引用错误 : google is not defined on using PrimeNG GMap,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43932010/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com