Postcode Integration for UK

Ok lets open this discussion here in an attempt to integrate the Postcode system with using google maps and some scripting.

In theory it wouldnt just be UK would it?
Once the core is figured adapting for other countries shouldnt be such a big job would it?
Just thinking about everyone else :slight_smile:

As for scripting I cant be much help Im afraid, not something ive ever looked at :-/

@JTRTech I am looking at google maps api and we should be able to get nearby information with postcode. I think we can use place id to generate it. Example you can enter POSTcode and it will give results nearby that postcode and you can even define the rank it returns the results.

Example:

google.maps.places.RankBy.DISTANCE. This option
sorts results in ascending order by their distance from the specified
location

it can even be sorted by types example of types supported are here:

https://developers.google.com/places/supported_types

1 Like

So what comes back on that query if you were to use that postcode I sent?

I have not built it yet so I dont know. I am just studying the api. Right now we need to find web support for this because the library is not included in SambaPOS yet. Although if we can convince @emre how useful it is he might include it. Let me study it more though there could be easier way to do it.

Fair enough, sorry, like I said this type of codeing is a little over my head

Actually you know what postal_code is supported so we may be able to do it with just web query.

Looking at that link Im not sure if places if the right source.
My understanding is places are business that list their business on google places within google maps…

We would not be using it we would be using the geolocation API.

Results would return as JSON data and we can read and parse this data with SambaPOS.

Need to get the free API key first.

I see what you mean so process would be; Postcode --> Place ID --> Address based on Place ID ?

No we will just use the web geolocation API. No more places… i read further into it and it should return the data we need.

Google Maps Geolocation API ?

Type this in your browser.

https://maps.googleapis.com/maps/api/geocode/json?components=postal_code:EC1Y|country=:GB&key=AIzaSyBPim1IKs10ovTDkWgtKKjEx5EyS3D8r1Q

{
   "results" : [
      {
         "address_components" : [
            {
               "long_name" : "EC1Y",
               "short_name" : "EC1Y",
               "types" : [ "postal_code_prefix", "postal_code" ]
            },
            {
               "long_name" : "London",
               "short_name" : "London",
               "types" : [ "locality", "political" ]
            },
            {
               "long_name" : "London",
               "short_name" : "London",
               "types" : [ "postal_town" ]
            },
            {
               "long_name" : "Greater London",
               "short_name" : "Gt Lon",
               "types" : [ "administrative_area_level_2", "political" ]
            },
            {
               "long_name" : "United Kingdom",
               "short_name" : "GB",
               "types" : [ "country", "political" ]
            }
         ],
         "formatted_address" : "London EC1Y, UK",
         "geometry" : {
            "bounds" : {
               "northeast" : {
                  "lat" : 51.52629289999999,
                  "lng" : -0.0860567
               },
               "southwest" : {
                  "lat" : 51.5203141,
                  "lng" : -0.1121881
               }
            },
            "location" : {
               "lat" : 51.52351420000001,
               "lng" : -0.0917564
            },
            "location_type" : "APPROXIMATE",
            "viewport" : {
               "northeast" : {
                  "lat" : 51.52629289999999,
                  "lng" : -0.0860567
               },
               "southwest" : {
                  "lat" : 51.5203141,
                  "lng" : -0.0981325
               }
            }
         },
         "place_id" : "ChIJ-UjItkgbdkgRi0VKn7KManY",
         "types" : [ "postal_code_prefix", "postal_code" ]
      }
   ],
   "status" : "OK"
}

Yes we are getting somewhere… its not exactly the results we need but its a start so now we just need to go further

Thats the result from a search for EC1Y ?

That is a basic result yes…but thats not all we can do. I used bare minimum of options just to test it. It worked so thats good. So now we need to find how to pull all addresses nearby. We will do that with reverse geocoding.

Sure, why note :confounded: glad you understand lol

My postcode gives
formatted_address" : “Todenham, Moreton-in-Marsh, Gloucestershire GL56 9NY, UK”,
Same as what comes up in google maps webpage.

Are you saying you could get a list of address in the area?

Now put this in:

https://maps.googleapis.com/maps/api/geocode/json?latlng=51.5246325,-0.09213969999999999&postal_code=EC1Y%208ST&key=AIzaSyBPim1IKs10ovTDkWgtKKjEx5EyS3D8r1Q

1 Like

Wow ok so got full address, how do you get to that from postcode?
The links uses long & lat but postcode is obviously an larger area,

Did you pick those coordinates?

Obviously the ideal result would be like what many big websites have where you put postcode and it gives you a list of the 5-40+ addresses for that postcode.

Imagine these will generally be done using address database from post office website but that very expencive, especially if you can resolve addresses via google API for free.

Even if it just gave the street or couple of streets and you put number in would be as good. I mean you have to look through list for number anyway so no long just to take address to street level and manually do number,