react- google-maps "Google не определен" - PullRequest
1 голос
/ 06 мая 2020

Я использую response- google-maps в одном из моих проектов реагирования. Но я получаю эту ошибку:

google is not defined

Я пробовал несколько других решений из stack-overflow , но ни одно из них не помогло мне. Вот мой код:

/* global google */
import React, { useState } from 'react'
import { GoogleMap, Marker, InfoWindow, HeatmapLayer, LoadScript } from '@react-google-maps/api';
import { markerPosition } from "./MapData";
... // other code

const ExampleTraffic = (props) => {

 ... // other code

  return (
    <LoadScript
      id="script-loader"
      googleMapsApiKey="My Api Key"
      region="BD"
      libraries={libraries}
    >
      <GoogleMap
        id='example-map'
        mapContainerStyle={{ height: "100vh", width: "100vw" }}
        zoom={13}
        center={{
          lat: 23.684994,
          lng: 90.356331
        }}
        clickableIcons={true}
      >
        ... // other code

        <HeatmapLayer data={[
                new google.maps.LatLng(22.862257, 22.862257),
                new google.maps.LatLng(22.853746, 89.534611),
                new google.maps.LatLng(22.847735, 89.537359),
                new google.maps.LatLng(22.845773, 89.551920),
                new google.maps.LatLng(22.861434, 89.534056),
                new google.maps.LatLng(22.864945, 89.514299),
                new google.maps.LatLng(22.868741, 89.527406),
                new google.maps.LatLng(22.866369, 89.528873),
                new google.maps.LatLng(22.857052, 89.547997),
                new google.maps.LatLng(22.845172, 89.530171),
                new google.maps.LatLng(22.854094, 89.562946),
                new google.maps.LatLng(22.868963, 89.507291),
                new google.maps.LatLng(22.871177, 89.547143),
                new google.maps.LatLng(22.897430, 89.513818)
         ]}
         />
      </GoogleMap>
    </LoadScript >
  );
}

export default ExampleTraffic;

Что не так с моим кодом? Любая помощь будет принята с благодарностью.

1 Ответ

0 голосов
/ 22 мая 2020

Проблема решена путем использования

new window.google.maps.LatLng(22.862257, 22.862257),
new window.google.maps.LatLng(22.853746, 89.534611),

вместо

new google.maps.LatLng(22.862257, 22.862257),
new google.maps.LatLng(22.853746, 89.534611),
...