Easiest Way to Implement Heatmaps in your React applications

To implement Heatmaps visualization in react apps, we need

Google Maps API key

google-map-react package

To get Google Maps API key, visit this page and follow the instructions.

As mentioned above, we use google-map-react package.
You can install…


This content originally appeared on DEV Community and was authored by roopantj

To implement Heatmaps visualization in react apps, we need

  1. Google Maps API key
  2. google-map-react package

To get Google Maps API key, visit this page and follow the instructions.

As mentioned above, we use google-map-react package.
You can install it by running,

npm i google-map-react

To get more info about this package, visit --><--

Now lets create a Heatmaps.js component.
Heatmaps.js

const Heatmaps = () => {
  return (
    <GoogleMapReact
      bootstrapURLKeys={{ key: YOUR_API_KEY }}
      defaultCenter={{ lat: DEFAULT_LAT, lng: DEFAULT_LNG }}
      defaultZoom={4}
      heatmap={{ positions: LIST_OF_POINTS, options: {} }}
      heatmapLibrary={true}
    ></GoogleMapReact>
  );
};

Pass the coordinates data in heatmap props and don't forget to set heatmapLibrary props true.

The LIST_OF_POINTS passed to positions[in heatmap prop] is an array of coordinates. Export coordinates array by creating a new file HeatmapPoints.js.
HeatmapPoints.js

export const LIST_OF_POINTS = [
  {
    lat: 9.9256235,
    lng: 78.1177802,
  },
  {
    lat: 9.920991599999999,
    lng: 78.1118825,
  },
  {
    lat: 9.9206833,
    lng: 78.1123521,
  },
  //Add as many coordinates you want.
]

Note
Make sure the container element of Heatmaps components has width and height. The map will fill the parent container, but if the container has no size, it will be collapsed.

Hope you find this useful!


This content originally appeared on DEV Community and was authored by roopantj


Print Share Comment Cite Upload Translate Updates
APA

roopantj | Sciencx (2021-12-26T19:39:38+00:00) Easiest Way to Implement Heatmaps in your React applications. Retrieved from https://www.scien.cx/2021/12/26/easiest-way-to-implement-heatmaps-in-your-react-applications/

MLA
" » Easiest Way to Implement Heatmaps in your React applications." roopantj | Sciencx - Sunday December 26, 2021, https://www.scien.cx/2021/12/26/easiest-way-to-implement-heatmaps-in-your-react-applications/
HARVARD
roopantj | Sciencx Sunday December 26, 2021 » Easiest Way to Implement Heatmaps in your React applications., viewed ,<https://www.scien.cx/2021/12/26/easiest-way-to-implement-heatmaps-in-your-react-applications/>
VANCOUVER
roopantj | Sciencx - » Easiest Way to Implement Heatmaps in your React applications. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/12/26/easiest-way-to-implement-heatmaps-in-your-react-applications/
CHICAGO
" » Easiest Way to Implement Heatmaps in your React applications." roopantj | Sciencx - Accessed . https://www.scien.cx/2021/12/26/easiest-way-to-implement-heatmaps-in-your-react-applications/
IEEE
" » Easiest Way to Implement Heatmaps in your React applications." roopantj | Sciencx [Online]. Available: https://www.scien.cx/2021/12/26/easiest-way-to-implement-heatmaps-in-your-react-applications/. [Accessed: ]
rf:citation
» Easiest Way to Implement Heatmaps in your React applications | roopantj | Sciencx | https://www.scien.cx/2021/12/26/easiest-way-to-implement-heatmaps-in-your-react-applications/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.