Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to draw a circle on a Google static map?

The static map API discusses paths, but no mention of circles. Is this possible? Thanks

like image 340
Aneil Mallavarapu Avatar asked Sep 22 '10 06:09

Aneil Mallavarapu


2 Answers

You can approximate a circle quite easily by using the computeOffset method which allows you to get the cooordinates along the circumference.

In this example I used increments of 8 degrees, so this will give 45 pairs of coordinates. For the circle sizes I was using the circles appeared nicely round in the static map. If you are using large circles, then simply change the increment to something smaller, eg j = j + 6.

The variable pathText is added to the rest of the web address required for the static map.

var pathText = '&path=';
var circumLatLng;

for (var j = 0; j < 361; j = j + 8) {

circumLatLng = google.maps.geometry.spherical.computeOffset(circle.getCenter(), circle.getRadius(), j);

pathText += circumLatLng.lat().toFixed(6) + ',' + circumLatLng.lng().toFixed(6) + '|';
}
like image 156
havelly Avatar answered Oct 02 '22 13:10

havelly


It is possible but you have to draw a shape with lots of sides to look like a circle.

Here is my example:

<img src="http://maps.google.com/maps/api/staticmap?size=600x500&path=fillcolor:0x0000FF|weight:3|color:0xFF0000|enc:ue{cI|rrH`@qs@hBis@nDyr@rF_r@tH_q@xJyo@zLgn@vNol@rPsj@lRmh@`Taf@tUqc@dWy`@nX{]vY{ZxZuWx[kTr\_Qh]oMz]}If^iFl^uBn^?n^tBd^hFz]|Ih]nMr\~Px[jTxZtWvYzZnXz]dWx`@tUpc@`T`f@lRlh@rPrj@xNnl@xLfn@xJxo@vH~p@rF~q@lDxr@hBhs@b@ps@c@ps@iBfs@mDxr@sF~q@wH`q@yJvo@yLfn@yNpl@sPpj@mRlh@aTbf@uUnc@eWx`@oX|]wYzZyZtWy[jTs\~Pi]lM{]|Ie^jFo^rBo^?m^sBg^kF{]}Ii]mMs\_Qy[kTyZuWwY{ZoX}]eWy`@uUoc@aTcf@mRmh@sPqj@wNql@{Lgn@yJwo@uHaq@sF_r@oDyr@iBgs@a@qs@&sensor=true" border="0"/>

Or try this link to view it

To generate this I used freemaptools.com

like image 35
sidonaldson Avatar answered Oct 02 '22 14:10

sidonaldson