[TYPO3-mvc] Re: How would you realize a radius search

Philipp philippwrann at gmx.at
Tue Feb 19 13:11:27 CET 2013


Okay, i think ive got some research to do :-)

At the moment my approach is a single sql query for my results. It works for the moment but i dont like it. 

public function findClosest($regionalObject, $excludeAllreadyDisplayed=FALSE, $andWhere = '',$limit=6) {
		
		if ($regionalObject instanceof \Pixelpoint\RegionalObject\Domain\Model\RegionalObject) {
		
			$lat = $regionalObject->getLatitude();
			$lng = $regionalObject->getLongitude();
			$table = $this->getTableName();
		
			$sql =
			"SELECT *,
			(
				acos(
					  sin(latitude)
					* sin($lat)
					+ cos(latitude)
					* cos($lat)
					* cos(longitude - $lng)
				) * 6371
			) AS distance
			FROM $table
			WHERE deleted = '0'
			AND hidden = '0'
			AND t3ver_oid = '0'
			$andWhere
			ORDER BY distance
			LIMIT $limit";
			
			$query = $this->createRawQuery();
			$query->getQuerySettings()->setReturnRawQueryResult(TRUE);
			$results = $query->statement($sql)->execute();
			
			return $this->mapResults($results);
			
		} else {
			throw new \UnexpectedValueException("regionalObject was not of type \\Pixelpoint\\RegionalObject\\Domain\\Model\\RegionalObject");
		}
		return NULL;
	}


More information about the TYPO3-project-typo3v4mvc mailing list