setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); $coords = Array( Array(123.45, -13.45),//some coodinates to remove from database ); $distance = 800 / 111139.0; // m / (m/deg) $json = Array(); foreach($coords as $coord) { $stmt = $db->prepare("SELECT *, SQRT(POW(ABS(? - lat),2) + POW(ABS(? - lng),2)) AS distance FROM markers WHERE POW(ABS(? - lat),2) + POW(ABS(? - lng),2) < POW(?,2) ORDER BY timestamp"); //$stmt->bindParam(":lat", $coord[0]); //$stmt->bindParam(":lng", $coord[1]); //$stmt->bindParam(":dist", $distance); $stmt->execute(Array($coord[0],$coord[1],$coord[0],$coord[1],$distance)); while($row = $stmt->fetch(PDO::FETCH_ASSOC)) { $row['lat'] = doubleval($row['lat']); $row['lng'] = doubleval($row['lng']); $row['alt'] = floatval($row['alt']); $row['hdop'] = intval($row['hdop']); $row['timestamp'] = strtotime($row['timestamp']); $row['format'] = date('d.m.Y H:i:s', $row['timestamp']); $json[] = $row; } $stmt = $db->prepare("DELETE FROM markers WHERE POW(ABS(? - lat),2) + POW(ABS(? - lng),2) < POW(?,2) ORDER BY timestamp"); $stmt->execute(Array($coord[0],$coord[1],$distance)); } ?> Arduino/PHP/MySQL & Google Maps