Skip to main content
14-Alexandrite
December 11, 2015
Question

Trying to extend current GMaps extension to use Google Maps Heatmap Function.

Hello Guys,

I am building an App which will have a Heatmap plotted in a map. There are some options that can be used, but to start it I plan to use Google Maps API to do so. I have 2 options:

  1. Use Fusion Tables: it is simple to use but the data has to be stored into a Google Fusion Table in order to be used. The good thing is that the heatmap is Server Side Computed which can be an important point to performance.
  2. Use HeatMap Function: has more flexibility as the data can be passed dinamically but it is client side computed.

I decided to go for the 2nd option but I cannot get it to work because it requires the Visualization library to be included and I do not know where I should put it. Does anyone have an idea of how to declare it? Here is what I have to include:

<script type="text/javascript"
 
src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&libraries=visualization&sensor=true_or_false">
</script>

For the code, I included an option into the extension's googlemap.ide file to add an option in the UI to Enable the HeatMap;

'ShowHeatMap': {

                'description': 'Show Fusion Tables HeatMap',

                'isBindingTarget': true,

                'defaultValue': false,

                'baseType': 'BOOLEAN'

                }

Also included in the googlemap.runtime file the API Call (almost copied and pasted from google):

if(this.getProperty('ShowHeatMap')){

    /* Data points defined as an array of LatLng objects */

  var heatmapData = [

   new google.maps.LatLng(37.782, -122.447),

   new google.maps.LatLng(37.782, -122.445),

   new google.maps.LatLng(37.782, -122.443),

   new google.maps.LatLng(37.782, -122.441),

   new google.maps.LatLng(37.782, -122.439),

   new google.maps.LatLng(37.782, -122.437),

   new google.maps.LatLng(37.782, -122.435),

   new google.maps.LatLng(37.785, -122.447),

   new google.maps.LatLng(37.785, -122.445),

   new google.maps.LatLng(37.785, -122.443),

   new google.maps.LatLng(37.785, -122.441),

   new google.maps.LatLng(37.785, -122.439),

   new google.maps.LatLng(37.785, -122.437),

   new google.maps.LatLng(37.785, -122.435)

  ];

  var heatmap = new google.maps.visualization.HeatmapLayer({

   data: heatmapData

  });

  heatmap.setMap(this.map);

   }

Thanks a lot

Ewerton

11 replies

emoreira14-AlexandriteAuthor
14-Alexandrite
December 11, 2015

Responding to my own questions:

I eventually found how to include the google visualization library in the Google Maps extension.

I had to replace the tag:

<FileResource description="" isRuntime="true" isDevelopment="false" type="JS" url="https://maps.google.com/maps/api/js?sensor=false"/>

by

<FileResource type="JS" url="https://maps.googleapis.com/maps/api/js?key=MY_APP_KEY&libraries=visualization" description="" isDevelopment="false" isRuntime="true"  />

Also had to create a Browser App key in the Google developer community and include my instance as an Allowed HTTP Referer.

Still struggling with 2 things still:

  1. How to add my localhost to the list of Allowed Referer
  2. How to make the AppKey an input variable that has to be passed, so I can distribute the extension without distributing my AppKey.

If somebody has an idea on how to do it, I appreciate any help

Cheers!

Ewerton

Translate
12-Amethyst
January 21, 2016

Hi Ewerton,

Did you get an answer to the second question? i.e. make the AppKey input variable?

Also, did you have any problems with the '&' in the FileResource's url above?  In my case, I'm looking to extend the google maps widget to include the drawing library, and was having problems (where TWX would error out importing the extension) around specifying the &libraries parameter.

Thanks!

Cletus

Translate
emoreira14-AlexandriteAuthor
14-Alexandrite
January 22, 2016

Hi  Cletus,

I did not get any feedback for the App key question, but I did figure out the syntax to use "&". Whenever you need to add it to an URL you have to actually add "&amp". So in your case it will be &amp;libraries=visualization"

Cheers

Ewerton

Translate