$radius = 200;
$lat = mysql_real_escape_string($zipcode1->getLatitude());
$long = mysql_real_escape_string($zipcode1->getLongitude());
$q = Doctrine_Query::create()
->select("j.address, j.longitude, j.latitude, (3959 * acos(cos
(radians('".$lat."')) * cos(radians(latitude)) * cos(radians
(longitude) - radians('".$long."')) + sin(radians('".$lat."')) * sin
(radians(latitude)))) AS distance")
->from("Job j")
->having("distance < ?", $radius)
->orderBy("distance desc");
$results = $q->execute();
Found this here:
http://groups.google.com/group/doctrine-user/browse_thread/thread/5f4042649c9fa275
I guess a more "symfony" way to do would be to edit the models so there is a functions such as:
$distance = $locationModel->DistanceFrom($anotherLocation);
$locations = LocationModel::GetLocationsClosestTo($lat, $long);
For my app I stored lat/long as decimals like so:
latitude: {type: decimal(4), scale: 4}
longitude: {type: decimal(4), scale: 4}
Because google maps api returns lats/longs with up to 4 decimal places