my $get_insertions = $dbh->prepare("SELECT `inserate`.*, `users`.`postleitzahl`, `users`.`vorname`, `plz_coords`.`stadt`, (6378.137 * ACOS(sin(`plz_coords`.`lat_rad`) * SIN(?) + COS(`plz_coords`.`lat_rad`) * COS(?) * cos(? - `plz_coords`.`long_rad`))) AS `distance` FROM `users` `users`, `inserate`, `plz_coords` WHERE `users`.`postleitzahl` = `plz_coords`.`plz` AND `inserate`.`user` = `users`.`id` AND `inserate`.`art` = ? AND (6378.137 * ACOS(sin(`plz_coords`.`lat_rad`) * SIN(?) + COS(`plz_coords`.`lat_rad`) * COS(?) * cos(? - `plz_coords`.`long_rad`))) < 50 ORDER BY distance;");
$get_insertions->execute($$coordsref{'lat_rad'}, $$coordsref{'lat_rad'}, $$coordsref{'long_rad'}, ($$params{'art'} eq 'biete' ? 'suche' : 'biete'), $$coordsref{'lat_rad'}, $$coordsref{'lat_rad'}, $$coordsref{'long_rad'});
schmeiß raus, was bei dir nicht zutrifft, das ist aus einem alten projekt von mir und funktionierte eigentlich soweit wunderbar.
hier das sql für die plz_coords
CREATE TABLE plz_coords (
plz varchar(5) NOT NULL default '',
stadt varchar(255) NOT NULL default '',
lat_rad float NOT NULL default '0',
long_rad float NOT NULL default '0',
lat float NOT NULL default '0',
`long` float NOT NULL default '0',
PRIMARY KEY (plz)
) TYPE=MyISAM;
frag mich aber nicht, wie ich zu der umrechnung von lat zu lat_rad kam, ist lange her. wenn mich nicht alles täuscht, war's
$lat_rad = $lat_rad * $pi / 180;
ich bin ja kein großer mathematiker, ich hab mir das damals auch nur zusammengesucht und probiert, bis es zufriedenstellend lief.
ach so, die distance sollte dann in km sein. ja.\n\n
<!--EDIT|jan|1158099807-->