Hallo,
ich habe eine Datenbank von opengeodb und möchte dazu eine passende Umkreissuche erstellen welche soweit auch funktioniert nur extrem Serverlastig ist. Das Skript sieht so aus:
Was muss ich anderes machen damit der Server nicht so viel beansprucht wird?
ich habe eine Datenbank von opengeodb und möchte dazu eine passende Umkreissuche erstellen welche soweit auch funktioniert nur extrem Serverlastig ist. Das Skript sieht so aus:
PHP-Code:
$radius = 6368;
$plz = '10115';
$umkreis = 20;
$sql = 'SELECT
coo.lon,
coo.lat
FROM geodb_coordinates AS coo
INNER JOIN geodb_textdata AS textdata
ON textdata.loc_id = coo.loc_id
WHERE
textdata.text_val = "' . mysql_real_escape_string($plz) . '"
AND textdata.text_type = "500300000"
';
$re = mysql_query($sql,$dbverbindung2);
if (mysql_num_rows($re) != 1) {
die($plz . ' wurde nicht gefunden.');
}
list($lon, $lat) = mysql_fetch_row($re);
$rad_l = $lat / 180 * M_PI;
$rad_b = $lon / 180 * M_PI;
###habe ich eingebaut damit er nicht überall suchen muss###
$latp=$lat+5;
$latm=$lat-5;
$lonp=$lon+5;
$lonm=$lon-5;
##########
$query = "SELECT loc_id, (
".$radius." * SQRT(2*(1-cos(RADIANS(lon)) *
cos(".$rad_b.") * (sin(RADIANS(lat)) *
sin(".$rad_l.") + cos(RADIANS(lat)) *
cos(".$rad_l.")) - sin(RADIANS(lon)) * sin(".$rad_b.")))) AS Distance
FROM geodb_coordinates
WHERE lat>='$latm' and lat<='$latp'and lon>='$lonm' and lon<='$lonp'
Having Distance <= ".$umkreis."
ORDER BY Distance
";
$sql = mysql_query($query,$dbverbindung2)or die(mysql_error());
while( $erg = mysql_fetch_object($sql) ) {
echo $erg->loc_id."<br>";
}
Kommentar