Ajax APIs available for Integr8 web services
 
 

Ajax APIs available for Integr8 web services

by 0100804 26. January 2009 16:01

The Data8 technical team is pleased to announce the public availability of Ajax APIs for our Integr8 web services, allowing developers to add services such as postcode lookup, geocoding, telephone number lookup and validation and much more into their websites with no server-side coding.

Ajax Postcode Lookup

A simple postcode lookup can now be done in just a few lines of Javascript code:

  // Load the Postcode Lookup API.
  data8.load('AddressCapture');

  function doPostcodeLookup(postcode, houseNumber) {
    // Get the full address from the postcode and house number.
    var pclookup = new data8.addresscapture();
    pclookup.getfulladdresssimple('WebPerClick',
      postcode,
      houseNumber,
      pcLookupCallback);
  }

  function pcLookupCallback(result) {
    // Check that the lookup succeeded, and populate
    // the text boxes on the form.
    if (result.Status.Success) {
      $("#add1").value = result.Results[0].Address[0];
      $("#add2").value = result.Results[0].Address[1];
      $("#add3").value = result.Results[0].Address[2];
      $("#add4").value = result.Results[0].Address[3];
      $("#add5").value = result.Results[0].Address[4];
      $("#add6").value = result.Results[0].Address[5];
      $("#postcode").value = result.Results[0].Address[6];
    }
  }

A full implementation of our Ajax postcode lookup features ready to add to your website can be downloaded from our code samples page.

Accurate Ajax Geocoding of Postcodes

The Google Maps API provides Ajax geocoding. However, when using this with a postcode, it can produce wildly innaccurate results, placing a postcode several miles from its actual location (try the demo to see for yourself!). Using our drop-in replacement for the GClientGeocoder class, we can offer accurate geocoding of postcodes while still taking advantage of the Google Maps API geocoding for other items.

A simple page to place a marker over a postcode or place can be created with a simple bit of Javascript:

var map;
var geocoder;

function initializeMap() {
  if (GBrowserIsCompatible()) {
    // Create the map and geocoder as normal, but using
    // GData8ClientGeocoder instead of GClientGeocoder.
    map = new GMap2(document.getElementById("map_canvas"));
    geocoder = new GData8ClientGeocoder();

    // Get the textbox the user is going to type into,
    // and the "find" button they are going to click on.
    var textbox = document.getElementById("location");
    var find_btn = document.getElementById("find_btn");

    // When the user clicks the button, remove any existing
    // markers and request the location of the entered
    // postcode or place.
    GEvent.addDomListener(find_btn, "click", function() {
      map.clearOverlays();
      geocoder.getLatLng(textbox.value,
        showGeocoderResult);
    });
  }
}

function showGeocoderResult(result) {
  // Show the position of the entered
  // postcode or place on the map.
  if (result) {
    map.setCenter(result, 11);
    map.addOverlay(new GMarker(result));
  }
}

For more information on any of the available services, visit the Integr8 Web Services site, or see the Ajax developer page for details on using our web services via Ajax.

Tags: ,

Technical

Comments are closed

RecentComments

Comment RSS
Skip Navigation Links
Request handled by server S1 for client 38.107.179.216 at 5/18/2012 7:36:53 AM