Skip to content

Instantly share code, notes, and snippets.

@kaystrobach
Created July 15, 2013 10:15
Show Gist options
  • Save kaystrobach/5998897 to your computer and use it in GitHub Desktop.
Save kaystrobach/5998897 to your computer and use it in GitHub Desktop.
public function findAllByCoordinatesDistance($coordinates, $distance) {
$earthRadius=6367.41;
if($distance[strlen($distance)-1] = 'm'){
$earthRadius=$earthRadius/1.609;
$distance = intval($distance);
}
// prepare for injections
$distance = floatval($distance);
$longitude = floatval($coordinates['longitude']) / 180 * M_PI; // Umrechnung von GRAD IN RAD
$latitude = floatval($coordinates['latitude']) / 180 * M_PI; // Umrechnung von GRAD IN RAD
$locations = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows (
'*,ROUND(' . $earthRadius.'*SQRT(2*(1-cos(RADIANS(latitude))*cos(' . $latitude . ')*(sin(RADIANS(longitude))*sin(' . $longitude . ')+cos(RADIANS(longitude))*cos(' . $longitude . '))-sin(RADIANS(latitude))*sin(' . $latitude . '))),1) AS distance',
'tx_zipcodes_domain_model_zipcode',
' 1 HAVING distance < ' . $distance,
'',
'distance' . ' '
);
$locationObjects = array();
foreach($locations as $location) {
// is just working for these Model Object, because of their magick constructor :D
$locationObjects[] = new Tx_Zipcodes_Domain_Model_ZipCode($location);
}
return $locationObjects;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment