Fetch Latitude Longitude by passing postcodes to maps.google.com using Javascript

前端 未结 6 1982
一向
一向 2020-12-14 12:18

I have Postcode in my large database, which contains values like SL5 9JH, LU1 3TQ etc.

Now when I am pasting above postcode to maps.google.com it\'s

6条回答
  •  既然无缘
    2020-12-14 12:54

    I know this is an old question, but just chipping in here with how I managed to achieve the same thing (in PHP, but should be fairly simple):

    1. I had a database of thousands of differently formatted postcodes. I cleaned each and every one of them up, uniformly, with this function and batch updates:

      function clean_postcode($postcode)
      {
          $out = preg_replace("/[^a-zA-Z0-9]/", '',strtoupper($postcode));
      
          if(strlen($out)>3) 
          {
              $out = substr($out, 0, (strlen($out) -3)).' '.substr($out, -3);
          }
      
          return $out;
      }
      
    2. Now that all postcodes are formatted uniformly, I downloaded and imported the Ordnance Survey's Code-Point data set (free) - https://www.ordnancesurvey.co.uk/opendatadownload/products.html

    3. I imported all their CSVs into my database in a separate codepoint table. From each CSV I imported the postcode, and the Eastings and Northings values.

    4. I ran the clean_postcode() function again in batch on all the Ordnance Survey data in my DB. About 50% of the postcodes have spaces in, and 50% don't - after this they were uniformly set.

    5. I ran the following PHP script on each and every postcode in the codepoint table and saved the Latitude and Longitude values returned into this table: http://bramp.net/blog/os-easting-northing-to-lat-long

    6. All done! You can now match up and pull a Lat/Lon value based on well-formatted postcodes.

    Further reading: http://www.deepbluesky.com/blog/-/converting-os-coodinates-into-longitude-latitude_7/

提交回复
热议问题