Javascript 标记群集器不是构造函数
我正在尝试在我的应用程序中实现Marker Clusterer。我在我的项目中安装了'@google/markerclusterer',并导入了它,如下所示。但是,我收到了错误:core.js:4002 error TypeError:_google_markerclusterer_网页包_IMPORTED_MODULE_7__不是构造函数。我不知道为什么我会得到这个,因为它应该是一个构造函数。这是我的密码Javascript 标记群集器不是构造函数,javascript,angular,typescript,google-maps-api-3,Javascript,Angular,Typescript,Google Maps Api 3,我正在尝试在我的应用程序中实现Marker Clusterer。我在我的项目中安装了'@google/markerclusterer',并导入了它,如下所示。但是,我收到了错误:core.js:4002 error TypeError:_google_markerclusterer_网页包_IMPORTED_MODULE_7__不是构造函数。我不知道为什么我会得到这个,因为它应该是一个构造函数。这是我的密码 import * as MarkerClusterer from '@google/ma
import * as MarkerClusterer from '@google/markerclusterer';
在initMap()中
for(变量i=0;i{
marker2.setAnimation(google.maps.Animation.BOUNCE);
设置超时(()=>{
marker2.setAnimation(空);
}, 1000);
打开(地图,标记2);
});
常量markerCluster=新的MarkerClusterer(地图,marker2,
{imagePath:'https://developers.google.com/maps/documentation/javascript/examples/markerclusterer/m' });
}
这是一个打字错误。Typescript不知道如何定位打字。您是否尝试过@types/markerclustererplus
每当我安装库时,我总是设法确保查找类型。此外,与谷歌分析和谷歌地图一样,将它们添加到src/tsconfig.json
中的tsconfig.json
也会有帮助:
"types": [
"googlemaps",
"google.analytics",
"node"
]
在项目根文件夹中的typings.d.ts
文件中:
declare var MarkerClusterer: any;
declare module 'google-maps' {
export = google.maps;
}
或者把它放在你的
import { ... } from '@angular/core';
declare var MarkerClusterer: any;
@Component()
如果您不想执行
typings.d.ts
或src/tsconfig.json
。尝试不同的选择。角度/类型脚本很挑剔。这是一个类型错误。Typescript不知道如何定位打字。您是否尝试过@types/markerclustererplus
每当我安装库时,我总是设法确保查找类型。此外,与谷歌分析和谷歌地图一样,将它们添加到src/tsconfig.json
中的tsconfig.json
也会有帮助:
"types": [
"googlemaps",
"google.analytics",
"node"
]
在项目根文件夹中的typings.d.ts
文件中:
declare var MarkerClusterer: any;
declare module 'google-maps' {
export = google.maps;
}
或者把它放在你的
import { ... } from '@angular/core';
declare var MarkerClusterer: any;
@Component()
如果您不想执行
typings.d.ts
或src/tsconfig.json
。尝试不同的选择。Angular/Typescript很挑剔。让@MukulSharma的评论更加突出。而不是这个
import * as MarketClusterer '@google/markerclusterer'
这样做
import MarkerClusterer from '@google/markerclusterer'
让@MukulSharma的评论更加突出。而不是这个
import * as MarketClusterer '@google/markerclusterer'
这样做
import MarkerClusterer from '@google/markerclusterer'
尝试-从“@google/MarkerClusterer”导入MarkerClusterer;取而代之的是*@MukulSharma,我从中得到了两个错误:TypeError:marker.getPosition不是MarkerClusterer.isMarkerInBounds处的函数,并且无法在MarkerClusterer.pushMarkerTo处的字符串“”上创建属性“isAdded”(MarkerClusterer.esm.js:429)尝试从“@google/MarkerClusterer”导入MarkerClusterer;取而代之的是*@MukulSharma,我从中得到了两个错误:TypeError:marker.getPosition不是MarkerClusterer.isMarkerInBounds处的函数,无法在MarkerClusterer.pushMarkerTo处的字符串“”上创建属性“isAdded”(MarkerClusterer.esm.js:429)喜欢这个答案。。。我没有从控制台得到任何错误,但是集群仍然没有出现在地图上,因为我无法说出它为什么没有出现。你有没有尝试过使用谷歌Chrome的资源来浏览它?设置断点并逐步查看是否存在值。这里有一个可能的答案:爱这个答案。。。我没有从控制台得到任何错误,但是集群仍然没有出现在地图上,因为我无法说出它为什么没有出现。你有没有尝试过使用谷歌Chrome的资源来浏览它?设置断点并逐步查看是否存在值。以下是一个可能的答案: