我正在尝试在我的应用程序中使用Google的Map API。但是,我收到以下编译器错误:
[ts] Property 'Place' does not exist on type 'typeof maps'. Did you mean 'places'?
现在,通常我可能会认为我错过了打字或依赖或某事;但奇怪的是,“Place”属性只是在上面几行正确地重新识别。
class gMap {
latLong: google.maps.LatLng;
window: google.maps.InfoWindow;
marker: google.maps.Marker;
map: google.maps.Map;
directionsService: google.maps.DirectionsService;
directionsDisplay: google.maps.DirectionsRenderer;
placeID: string;
place: google.maps.Place;
constructor(lat: number, long: number, place: string, info: string, mapEl: Element) {
this.latLong = new google.maps.LatLng(lat, long);
this.window = new google.maps.InfoWindow({ content: info });
this.placeID = place;
this.place = new google.maps.Place(place);
this.map = new google.maps.Map(mapEl, {
center: this.latLong,
zoom: 15
});
this.marker = new google.maps.Marker({ position: this.latLong, map: this.map, });
this.window.open(this.map, this.marker);
}
首次使用google.maps.Place(地址:google.maps.Place;)有效。构造函数中的一个(this.place = new google.maps.Place(place);)导致错误。
如果这个显而易见的事我道歉,我对TypeScript和Google Maps相对较新。任何指导将不胜感激。感谢。
答案 0 :(得分:1)
google.maps.Place
,根据Google Maps JavaScript API文档不是类,它是一个对象:
https://developers.google.com/maps/documentation/javascript/reference#Place
因此,您无法使用new
运算符来创建实例。您应该将其视为具有属性location
,placeId
和query
的纯JavaScript对象。