The function below creates a polygon square out of 4 points and I assume the last 5th point closed the squar, I need it to have at least 24 points and to make up a circle. Any ideas?
function getRadius($point="POINT(-29.8368 30.9096)", $radius=2)
{
$km = 0.009;
$center = "GeomFromText('$point')";
$radius = $radius*$km;
$bbox = "CONCAT('POLYGON((',
X($center) - $radius, ' ', Y($center) - $radius, ',',
X($center) + $radius, ' ', Y($center) - $radius, ',',
X($center) + $radius, ' ', Y($center) + $radius, ',',
X($center) - $radius, ' ', Y($center) + $radius, ',',
X($center) - $radius, ' ', Y($center) - $radius, '
))')";
$query = $this->db->query("
SELECT id, AsText(latLng) AS latLng, (SQRT(POW( ABS( X(latLng) - X({$center})), 2) + POW( ABS(Y(latLng) - Y({$center})), 2 )))/0.009 AS distance
FROM crime_listing
WHERE Intersects( latLng, GeomFromText($bbox) )
AND SQRT(POW( ABS( X(latLng) - X({$center})), 2) + POW( ABS(Y(latLng) - Y({$center})), 2 )) < $radius
ORDER BY distance
");
if($query->num_rows()>0){
return($query->result());
}else{
return false;
}
}
Below the the js version and this works perfect
var findCirclePolygons = function(point, r)
{
var d2r = Math.PI / 180;
this.circleLatLngs = new Array();
numPoints = 24;
var circleLat = r * 0.009; // Convert degrees into km
var circleLng = circleLat / Math.cos(point.lat() * d2r);
for (var i = 0; i < numPoints + 1; i++) {
var theta = Math.PI * (i / (numPoints / 2));
var vertexLat = point.lat() + (circleLat * Math.sin(theta));
var vertexLng = parseFloat(point.lng()) + parseFloat(( circleLng * Math.cos(theta)));
var vertextLatLng = new google.maps.LatLng(vertexLat, vertexLng);
this.circleLatLngs.push(vertextLatLng);
}
// Set options
var options = {
paths: circleLatLngs,
strokeColor: "#0055ff",
strokeOpacity: 1,
strokeWeight: 1,
fillColor: "#0055ff",
fillOpacity: 0.35
};
// Return
return options;
};