Postcode Programming API Get Long/Lat from SOAP Web Service using PostZon Data

To get a "Postzon" Geographical Data address from our SOAP Web Service we do the following:

Distance between two postcodes

The distance between two postcodes can be returned. Simply call with Postcode and “Home postcode” provided in the parameters. Our service will then return the distance in km.  So approximate charges could be applied to a customer based on the straight line distance.

Postcode to Longitude/Latitude

This is the main use of PostZon data. Simply call with the target Postcode and the PostZon data service will return the Longitude and Latitude. Ideal for mapping and calculating distances.

Longitude/Latitude to Postcode

To get the PostZon record by Longtitude/Latitude, (closest within 10Km) set postcode to the "Longtitude|Latitude" (separated by |). The Postcode found will be returned in pz_postcode.

Town to Longitude/Latitude

To get the Longitude and Latitude of a Town, simply provide the Town name + “,SPACE“ + County in the postcode field. The Longitude and Latitude will then be returned. It is suggested that the town list is displayed using a AJAX search box.

SOAP Web Service get PostZon Data:

The following explains how to get geographical data from the PostZon data file.

Step 1 Sign up for trial

Simply use the "Sign Up for Trial" link at top right of this page to open a trial account.   We will then send you a data key, which is used to identify your account, when using the following service.

Step 2 Add SOAP reference to your project

The following web references give access to our SOAP web service

.NET Web Reference

https://www.SimplyLookupadmin.co.uk/WebService.asmx

WSDL Web Reference

https://www.SimplyLookupadmin.co.uk/WebService.asmx?WSDL

You should add this SOAP reference to your project.

Step 3 Call SOAP Web Service to get PostZon Data

The following code will call the SOAP Web Service to return "Postzon" Geographical Data for a given postcode.

Parameters

Parameter name Description
DataKey Datakey, which is available when account has been created, under the “DataKey” tab of the online account administrator page.
Username Only needed if for internal postcode address use
SearchType Set to “UK”
Postcode Postcode to search for. OR...
To get the PostZon record by OSRef, simply set postcode to the OSRef.
To get the PostZon record by Longtitude/Latitude, (closest within 10Km) set postcode to the "Longtitude|Latitude" (separated by |). The Postcode found will be returned in pz_postcode.
To get the Longitude and Latitude of a Town, simply provide the Town name + “,SPACE“ + County in the postcode field. The Longitude and Latitude will then be returned. It is suggested that the town list is displayed using a AJAX search box.

[Download town list]

homepostcode To calculate the distance to another postcode, supply the HOME postcode here, this is optional

Returns

Returns true if address search completed and General_credits_display_text contains summary of Credits/License status. Else errors reported in General_errormessage. 

PostZon Geographic data - Example Code


                        VB.NET   
                          
                          Dim HomePostcode as string 
                          ="PE132QL"
Dim PostcodeToGet as string = "PE132XQ"
Dim PostcodeSearch As New PostcodeWebService.WebService
Dim Address As PL_AddressRecord

'Ask for Address by ID
Address = PostcodeSearch.SearchForPostZonData(“My DataKey”, “TestComputer", "UK", PostcodeToGet,
                         HomePostcode)


If Address.AddressRecordGotWithoutError Then
   'Display results
   If Address.ErrorMessage <> "" Then MsgBox(Address.ErrorMessage)

      'Process the Address to text field
      Dim AddressText As String
      With Address
         AddressText + = "Longitude:" & .longitude_WGS84 & vbCrLf
         AddressText + = "Latitude:" & .latitude_WGS84 & vbCrLf
         AddressText + = "Distance Km:" & .GeoDistanceToHomePostcode & vbCrLf
      End With
      Me.TxtAddress.Text = AddressText
   Else
      'Display error (Account stuff mostly, i.e. No License)
      MsgBox(Address.ErrorMessage)
End If


                        C# .NET   
                          
                          uk.co.simplylookupadmin.www.WebService PostcodeSearch = new 
                            uk.co.simplylookupadmin.www.WebService();
uk.co.simplylookupadmin.www.PL_AddressRecord AddressesDataReturned = new
                                       uk.co.simplylookupadmin.www.PL_AddressRecord();


string datakey = Request.QueryString["datakey"].ToString();
string postcode = Request.QueryString["postcode"].ToString();
string userid = Request.QueryString["userid"].ToString();
string homepostcode = Request.QueryString["homepostcode"].ToString();


//Please note: Section 3.5 of the terms and conditions state: "The Customer, when using the Postcode Lookup service via Web Service, must make sure each user is identified by a unique computer name, in each call to the Web Service." In simple language this means that each user must be identified by a unique username.

//If the postcode address search is for External use then SET ComputerName = ""

//Do Search, on Postcode or two or more address fields
AddressesDataReturned = PostcodeSearch.SearchForPostZonData(datakey, userid, "UK", postcode,
                               homepostcode);


if (AddressesDataReturned.AddressRecordGotWithoutError == true)
{
   //Display results, no major error
   this.TxtResults.Text = AddressesDataReturned.ErrorMessage;

   string AddressText;
   AddressText = "Status:" + AddressesDataReturned.CreditsStatusText + "\n" + "\n";

   AddressText += "MailSort:" + AddressesDataReturned.MailSort + "\n";
   AddressText += "longitude_WGS84:" + AddressesDataReturned.longitude_WGS84 + "\n";
   AddressText += "latitude_WGS84:" + AddressesDataReturned.latitude_WGS84 + "\n";
   AddressText += "UK_os_reference:" + AddressesDataReturned.UK_os_reference + "\n";
   AddressText += "UK_OS_grid_east:" + AddressesDataReturned.UK_OS_grid_east + "\n";
   AddressText += "UK_OS_grid_north:" + AddressesDataReturned.UK_OS_grid_north + "\n";
   AddressText += "UK_NHS_code:" + AddressesDataReturned.UK_NHS_code + "\n";
   AddressText += "UK_NHS_region:" + AddressesDataReturned.UK_NHS_region + "\n";
   AddressText += "UK_country:" + AddressesDataReturned.UK_country + "\n";
   AddressText += "UK_IntroductionDate:" + AddressesDataReturned.UK_IntroductionDate + "\n";
   AddressText += "UK_county:" + AddressesDataReturned.UK_county + "\n";
   AddressText += "UK_district:" + AddressesDataReturned.UK_district + "\n";
   AddressText += "UK_ward:" + AddressesDataReturned.UK_ward + "\n";
   AddressText += "UK_wardstatus:" + AddressesDataReturned.UK_wardstatus + "\n";
   AddressText += "UK_county:" + AddressesDataReturned.UK_county + "\n";
   AddressText += "UK_gridstatus:" + AddressesDataReturned.UK_gridstatus + "\n";

   // long Distance = 0;

   // to do AddressesDataReturned.GeoDistanceToHomePostcode is a string and needs type casting?

   //If (length(AddressesDataReturned.GeoDistanceToHomePostcode)>0) Then
   // Distance = (long)(AddressesDataReturned.GeoDistanceToHomePostcode);
   // AddressText += "Distance:" + Distance + " km " + (long)(Distance / 1.609344) + " miles" + "\n";

   this.TxtResults.Text = AddressText;
}
else
{
   //Display error (Account stuff mostly)
   this.TxtResults.Text = AddressesDataReturned.ErrorMessage;
}

Where PostcodeSearch is a web reference to: https://www.SimplyLookupadmin.co.uk/WebService.asmx

More information on PostZon data, including detail information about the data returned.

Step 4 Testing

Final step is to test, to enable easy testing please use our special test postcodes.

Simply download the example code.   The code is in the "SOAP/VBNET 2010 PostZon" or "SOAP/VBNET 2003 PostZon" directory of our example downloads.

These two examples demonstrate postcode lookup software using PostZon data.

Data Returned

This type of license returns: (see example below)

Public UK_IntroductionDate As String
Public UK_OS_grid_east As String
Public UK_OS_grid_north As String
Public UK_county As String
Public UK_district As String
Public UK_ward As String
Public UK_gridstatus As String (accuracy of the geographic data)
Public UK_country As String
Public UK_wardstatus As String
Public UK_NHS_code As String
Public UK_NHS_region As String
Public longitude_WGS84 As String
Public latitude_WGS84 As String
Public UK_os_reference As String
Public GeoDistanceToHomePostcode As String
           'Distance from "Home Postcode" in km

More infromation on Geographic data