下面的函数用 4 个点创建一个多边形正方形,我假设最后 5 个点闭合了正方形,我需要它至少有 24 个点并组成一个圆。有任何想法吗?
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;
}
}
在 js 版本之下,这很完美
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;
};