Thanks Graham, That could come in useful allied with John's post re Goocle maps earlier today.
Dave Crozier -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Graham Brown (CompSYS) Sent: 16 October 2007 09:32 To: ProFox Email List Subject: RE: [NF] Ordnance survey maps x/y coordinates PHP code The hwz_postcodes table contains fields outcode (postcode), longitutde, latitude, x, y The outcode is just the first bit of the postcode ie LE1,LE2,LE3 and contains about 2000 entries. I found a website where these were all listed and could be copied straight off, will see if I can find it again. It receives a post field called POSTCODE. The customers table is just a list of stockists (name, address, phone, fax, postcode etc etc). I've got to fix a bug with this code whereby if the postcode is not in hwz_postcodes it shows rubbish. <?php //connect to database $db = mysql_connect ("xxx", "xxx", "xxx") or die ('I cannot connect to the database because: ' . mysql_error()); mysql_select_db ("xxx",$db); $distance_tmp = 100000000000; $postcodeA = $_POST['postcode']; $length = strlen($postcodeA); if ($length > 4){ $temp1 = wordwrap($postcodeA, 4, "/", true); $temp=strtoupper($temp1); list($postcodeA, $rubbishA) = split('[/.-]',$temp); } //x and y of A $string = sprintf("SELECT * FROM hwz_postcodes WHERE outcode='%s'", mysql_real_escape_string($postcodeA)); $query = mysql_query($string); $array = mysql_fetch_row($query); $xA = $array[2]; $yA = $array[3]; $i = 0; $main_query = mysql_query("SELECT postcode FROM customers"); while ($main_array = mysql_fetch_array($main_query)) { if ($main_array[0]) { $postcodeB = $main_array[0]; $postcode = $main_array[0]; $temp2 = wordwrap($postcodeB, 4, "/", true); $temp3=strtoupper($temp2); list($postcodeB, $rubbishB) = split('[/.-]',$temp3); //x and y of B $string = sprintf("SELECT * FROM hwz_postcodes WHERE outcode='%s'", mysql_real_escape_string($postcodeB)); $query = mysql_query($string); $array = mysql_fetch_row($query); $xB = $array[2]; $yB = $array[3]; //distance $x = $xB - $xA; $y = $yB - $yA; $distance = sqrt(($x * $x) + ($y * $y)) / 1609.344; $distance =sprintf("%10.1f\n", $distance); if ($distance < $distance_tmp) { $distance_tmp = $distance; $postcode_tmp = $postcode; } $i++; } } $string = sprintf("SELECT * FROM customers WHERE postcode='%s'",mysql_real_escape_string($postcode_tmp)); $query = mysql_query($string); $array = mysql_fetch_row($query); ?> <?php echo nl2br("<p style=\"font-size:14px; text-align: right;\">Your nearest store is <b>"); if ($array[8]){ echo"<a href=\"http://".$array[8]."\">"; } echo nl2br($array[1]."</a></b></p>".$array[2]." ".$array[3]." ".$array[4]." ".$array[5]."<br>".$array[6]); if ($array[7]) { echo "Telephone: ".$array[7]; } ?> Regards Graham -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of Dave Crozier Sent: 16 October 2007 07:56 To: 'ProFox Email List' Subject: RE: [OT] Ordnance survey maps x/y coordinates Graham, Shouldn't really be [OT] as other developers may be interested. I'd make it [NF] Dave Crozier -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Graham Brown (CompSYS) Sent: 15 October 2007 18:58 To: ProFox Email List Subject: [OT] Ordnance survey maps x/y coordinates Hi all Completely off topic this one. I've inherited some really neat PHP code today which takes a UK postcode (zipcode!) and looks in a database to find the nearest database record with that postcode. The php code is basically for entering your postcode and finding where the nearest stockist is to your location. It does this by using the Ordnance Survey X/Y coordinates and looking up the first part of the postcode "LE4" to find the X/Y. Mainland UK postcodes can be easily looked up with http://www.streetmap.co.uk/streetmap.dll?GridConvert?name=CV32%204AT&type=Po stcode The code works really well but before I port it to VFP I've tested it with Jersey (little place between the mainland uk and france!) and it fails. Although I have the JE2 postcode I can't find anywhere which publishes the OS x/y for the channel islands. Would anyone happen to know if Ordnance Survey is one of the quirky mainland uk things or where i can find OS cordinates for outside the mainland uk. ps if anybody wants the php code let me know! Cheers Graham [excessive quoting removed by server] _______________________________________________ Post Messages to: [email protected] Subscription Maintenance: http://leafe.com/mailman/listinfo/profox OT-free version of this list: http://leafe.com/mailman/listinfo/profoxtech Searchable Archive: http://leafe.com/archives/search/profox This message: http://leafe.com/archives/byMID/profox/[EMAIL PROTECTED] ** All postings, unless explicitly stated otherwise, are the opinions of the author, and do not constitute legal or medical advice. This statement is added to the messages for those lawyers who are too stupid to see the obvious.

