Lat:$lat Lng: $lng"; // === Try to open the file for read access === $file = fopen("map11.dat", "r") or exit("Unable to open file!"); // === Read the data === $i = 0; while(!feof($file)) { $a = fgets($file); $parts = explode(":",$a); $lats[$i] = $parts[0]; $lngs[$i] = $parts[1]; $htmls[$i] = $parts[2]; $labels[$i] = $parts[3]; $i++; } fclose($file); // == ??? is there no "array.length" in PHP ??? === $len = $i - 1; // === Search for the nearest marker === // For efficiency, I compare the square of the distance // Rather than performing sqrt() on everything // // Distances are in "degrees" here. Should really use real distances // $best = 0; $bestdist = 99999; for ($i=0; $i<$len; $i++) { $dist2 = pow($lats[$i] - $lat, 2) + pow($lngs[$i] - $lng, 2); if ($dist2 < $bestdist) { $bestdist = $dist2; $best = $i; } } // === Set the MIME type to XML === // == Any "exit" output before this line is HTML header("Content-type: text/xml"); // === Output the nearest marker === echo ''; echo ''; echo ''; ?>