GBG Developers

Guides   |   Using the Address Service

Using the Address Service

The address service can be used for purposes such as rapidly entering an address manually. A typical scenario would be to allow the user to begin typing in the postcode, and a list of addresses would be displayed as they type. From the list of addresses, the user could select one and the SDK would then query the GBG Identity Solution to retrieve the full address details to fully populate all fields in a form.

Here’s an example of how to use the Address Service with JavaScript:

function do_address() {
    return window.sdkInstance.performActivity({
        activity: GBG.IDaaS.Activities.AddressLookup
    })
	  .then((obj) => {
		console.log(obj);
	   })
        .then(() => console.log("done address capture"))
}

The screenshot below shows on the left what occurs as the user begins to type the text Baker Str. When the user decides to click on one of the addresses, the display will change to the view shown on the right, with additional detail filled in for the chosen address.



You can extract the results from the activity meta data. To do that, use the Chrome Developer Tools console view to see the formatted output. Here’s an example:

{
  "activity": "address-lookup",
  "behaviour": {
    "fulfilled": "Manual",
    "unfulfilled": "Error"
  },
  "parameters": {},
  "id": "ebdeefb1-670f-4ea4-8b9a-d09e5583c0ad",
  "order": 0,
  "state": "Complete",
  "meta": {
    "addressFields": {
      "AdministrativeArea": "Doncaster",
      "Country": "GBR",
      "DependentLocality": "South Yorkshire",
      "Locality": "Doncaster",
      "PostalCode": "DN84 2RF",
      "Premise": "122",
      "Thoroughfare": "The Drive"
    },
    "type": "ADDRESSLOOKUP"
  }
}