Draw multiple circles in Google Maps
Posted
by snorpey
on Stack Overflow
See other posts from Stack Overflow
or by snorpey
Published on 2010-04-17T09:35:42Z
Indexed on
2010/04/17
9:43 UTC
Read the original article
Hit count: 413
Hi.
I want to draw multiple circles on a map, using the Google Maps API anj jQuery.
The following code works as long as the line with drawMapCircle() is commented out (The markers are positioned correctly).
What's wrong with my code?
$.getJSON(
"ajax/show.php",
function(data)
{
$.each(data.points, function(i, point)
{
map.addOverlay(new GMarker(new GLatLng(point.lat, point.lng)));
drawMapCircle(point.lat, point.lng, 0.01, '#0066ff', 2, 0.8, '#0cf', 0.1);
});
}
);
function drawMapCircle(lat, lng, radius, strokeColor, strokeWidth, strokeOpacity, fillColor, fillOpacity)
{
var d2r = Math.PI / 180;
var r2d = 180 / Math.PI;
var Clat = radius * 0.014483; // statute miles into degrees latitude conversion
var Clng = Clat/Math.cos(lat * d2r);
var Cpoints = [];
for (var i = 0; i < 33; i++)
{
var theta = Math.PI * (i / 16);
Cy = lat + (Clat * Math.sin(theta));
Cx = lng + (Clng * Math.cos(theta));
var P = new GLatLng(Cy, Cx);
Cpoints.push(P);
}
var polygon = new GPolygon(Cpoints, strokeColor, strokeWidth, strokeOpacity, fillColor, fillOpacity);
map.addOverlay(polygon);
}
© Stack Overflow or respective owner