The size of circles on Google Maps

On the ramblings site you can see how to create Google Maps straight from Excel, including adding circle overlays. By default, the code generated to plot these circles looks like this.

if (sz) {
      var circle =  {
         strokeColor: color,
         strokeOpacity: 0.8,
         strokeWeight: 1,
         fillColor: color,
         fillOpacity: 0.20,
         map: gMap,
         center: p,
         radius: parseFloat(sz), 
      };

 

Where sz and color are variables that have been inherited from columns in your input Excel data.

Calculating an appropriate size for circles. 
Normally you’ll be generating a size value for each data item based on some property like population or whatever your map is supposed to be representing, and overlaid circles would vary in size relative to your data values. At first glance it seems easy enough.

However, the impression of the size of a circle comes from its area , but what google maps needs is a radius. Thinking back to basic math, the area of a circle is calculated as

PI() * POWER(r,2)

So clearly you can’t use a simple linear formula to generate your size data.


Calculating a relative radius
The radius of a circle is calculated from the area by this formula

SQRT(a/PI())

so to be able to get the effect you want, you should apply this formula to your linear data (a) to generate a relative radius for each data item.


Scale
Obviously your scale (the final size of the circle generated), should be appropriate for the geography being shown.When you specify the radius of a circle to be plotted on Google Maps, we’re talking about meters, and 1 kilometer is just over .6 of a mile, so you will need to multiply the radius by some number of meters, giving a final formula of

SQRT( (your linear calculated size) / PI()) * (some number of meters)

For more on Google Maps from Excel, see the ramblings site.

 

About brucemcp 225 Articles
I am a Google Developer Expert and decided to investigate Google Apps Script in my spare time. The more I investigated the more content I created so this site is extremely rich. Now, in 2019, a lot of things have disappeared or don’t work anymore due to Google having retired some stuff. I am however leaving things as is and where I came across some deprecated stuff, I have indicated it. I decided to write a book about it and to also create videos to teach developers who want to learn Google Apps Script. If you find the material contained in this site useful, you can support me by buying my books and or videos.