<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: roopantj</title>
    <description>The latest articles on DEV Community by roopantj (@roopan_tj).</description>
    <link>https://dev.to/roopan_tj</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F778228%2F0ebd973c-befa-42f6-bcb0-4344b9d2a740.png</url>
      <title>DEV Community: roopantj</title>
      <link>https://dev.to/roopan_tj</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/roopan_tj"/>
    <language>en</language>
    <item>
      <title>Easiest Way to Implement Heatmaps in your React applications </title>
      <dc:creator>roopantj</dc:creator>
      <pubDate>Sun, 26 Dec 2021 19:39:38 +0000</pubDate>
      <link>https://dev.to/roopan_tj/easiest-way-to-implement-heatmaps-in-your-react-applications-40p6</link>
      <guid>https://dev.to/roopan_tj/easiest-way-to-implement-heatmaps-in-your-react-applications-40p6</guid>
      <description>&lt;p&gt;To implement Heatmaps visualization in react apps, we need &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Google Maps API key
&lt;/li&gt;
&lt;li&gt;google-map-react package&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;To get Google Maps API key, visit this &lt;a href="https://developers.google.com/maps/documentation/javascript/get-api-key"&gt;page&lt;/a&gt; and follow the instructions.&lt;/p&gt;

&lt;p&gt;As mentioned above, we use &lt;strong&gt;google-map-react&lt;/strong&gt; package.&lt;br&gt;
You can install it by running,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm i google-map-react
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To get more info about this package, visit &lt;a href="https://www.npmjs.com/package/google-map-react"&gt;--&amp;gt;&amp;lt;--&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now lets create a Heatmaps.js component.&lt;br&gt;
&lt;strong&gt;Heatmaps.js&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const Heatmaps = () =&amp;gt; {
  return (
    &amp;lt;GoogleMapReact
      bootstrapURLKeys={{ key: YOUR_API_KEY }}
      defaultCenter={{ lat: DEFAULT_LAT, lng: DEFAULT_LNG }}
      defaultZoom={4}
      heatmap={{ positions: LIST_OF_POINTS, options: {} }}
      heatmapLibrary={true}
    &amp;gt;&amp;lt;/GoogleMapReact&amp;gt;
  );
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Pass the coordinates data in &lt;strong&gt;heatmap&lt;/strong&gt; props and don't forget to set &lt;strong&gt;heatmapLibrary&lt;/strong&gt; props &lt;em&gt;true&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;LIST_OF_POINTS&lt;/strong&gt; passed to positions[in heatmap prop] is an array of coordinates. Export coordinates array by creating a new file HeatmapPoints.js.&lt;br&gt;
&lt;strong&gt;HeatmapPoints.js&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;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.
]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;&lt;br&gt;
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.&lt;/p&gt;

&lt;p&gt;Hope you find this useful!&lt;/p&gt;

</description>
      <category>react</category>
      <category>heatmaps</category>
      <category>googlemapreact</category>
      <category>javascript</category>
    </item>
  </channel>
</rss>
