add cordinatesquerries
This commit is contained in:
@@ -29,12 +29,47 @@ class SpsApi extends Api {
|
||||
}
|
||||
|
||||
/**
|
||||
* Method stert a sps-query
|
||||
* Method start a sps-query(alias)
|
||||
* @param array $queryArgs
|
||||
* @return array[num] [assoc]
|
||||
*/
|
||||
public function sendSpsQuery($queryArgs = array()) {
|
||||
return $this->sqlManager->sendSpsQuery($queryArgs);
|
||||
public function sendSpsAliasQuery($queryArgs = array()) {
|
||||
|
||||
return $this->sqlManager->sendSpsAliasQuery($queryArgs);
|
||||
}
|
||||
|
||||
private $range = 1;
|
||||
|
||||
public function sendSpsCoordinateQuery($queryArgs = array()) {
|
||||
if (!array_key_exists("longitude", $queryArgs) || !array_key_exists("latitude", $queryArgs)) {
|
||||
return null;
|
||||
}
|
||||
$latitude = $queryArgs["latitude"];
|
||||
$longitude = $queryArgs["longitude"];
|
||||
|
||||
if (!$this->validLatitude($latitude) || !$this->validLongitude($longitude)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$queryArgs["poly"] = $this->createPolygon($latitude, $longitude, $this->range);
|
||||
return $this->sqlManager->sendSpsCoordinateQuery($queryArgs);
|
||||
}
|
||||
|
||||
private function validLongitude($string) {
|
||||
|
||||
return ctype_digit(str_replace(".", "", $string));
|
||||
}
|
||||
|
||||
private function validLatitude($string) {
|
||||
return ctype_digit(str_replace(".", "", $string));
|
||||
}
|
||||
|
||||
private function createPolygon($latitude, $longitude, $range) {
|
||||
$minLat = $latitude - $range;
|
||||
$minLong = $longitude - $range;
|
||||
$maxLat = $latitude + $range;
|
||||
$maxLong = $longitude + $range;
|
||||
return "GeomFromText('Polygon(($minLat $minLong,$minLat $maxLong,$maxLat $maxLong,$maxLat $minLong,$minLat $minLong))'";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user