小编Lui*_*uis的帖子

“窗口”类型上不存在属性“google”

我正在尝试在 ReactJS 上使用 Google Maps Api 和尽可能少的 npm 模块。所以我自己将脚本添加到窗口对象中。但是打字稿在一句话之后跳了起来:“属性 'google' 在类型 'Window' 上不存在”。

我尝试在 Window 界面中添加一个属性 google: any ,但它不起作用,而且我在 google 类型中找不到合适的界面。

这是我的代码:

private initMap = () => {
this.setState({
  map: new window.google.maps.Map(document.getElementById("map"), {
    center: {
      lat: this.state.userPosition.lat,
      lng: this.state.userPosition.lng
    },
    zoom: this.state.zoom,
    mapTypeId: window.google.maps.MapTypeId.ROADMAP,
    disableDefaultUI: true,
    zoomControl: true
  })
});

this.setState({
  rangeCircle: new window.google.maps.Circle({
    strokeColor: "#007AFF",
    strokeOpacity: 0.8,
    strokeWeight: 2,
    fillColor: "#007AFF",
    fillOpacity: 0.35,
    map: this.state.map,
    center: {
      lat: this.state.userPosition.lat,
      lng: this.state.userPosition.lng
    },
    radius: this.state.radius * 1000
  })
});

this.setState({ …
Run Code Online (Sandbox Code Playgroud)

google-maps-api-3 typescript reactjs

7
推荐指数
2
解决办法
8413
查看次数

标签 统计

google-maps-api-3 ×1

reactjs ×1

typescript ×1