以下职能在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;
};