| Javascript Geocoder - UK Geocoding Website Integration |
|
|
|
This section explains how to use the Javascript Geocoder for iShareMaps On Demand. Using this will enable you to tightly integrate geocoding capabilities into your website.
IntroductionTo use the Javascript Geocoder you will need a licence key. A licence key is provided when you subscribe to an iShareMaps On Demand service. We offer a free trial so you can try it before you buy it. Please see the subscriptions page for more details.
The only file you will need to include into your web page is our geocoder.js file. Please see example below:
<script type="text/javascript" src="http://www.astuntechnology.com/isharemaps_on_demand/v2_1/js/geocoder.js"> </script>
You are now ready to begin Javascript geocoding!
The main Javascript function to search for an address is defined as:
This function returns the results in a multi dimensional array. The following is some sample javascript detailing the call to the web service via Javascript //Test function to search for an array of formatted addressesfunction test_searchFormattedAddresses(){ //Set the method variable method = "searchFormattedAddress"; //To search for a Postcode add1 = new atAddress("","","","KT18 5AD", ""); //or for a town (globally) add1 = new atAddress("","Epsom","Surrey","", "UK"); var licensekey = 'js0000-0000-0000'; // Input your license key here var recordcount = 10; //an issue exists with this parameter but a max of 20 matches will be returned var threshold = 0.85; //match rate var coordsys = 1; //Call the web service & get the results searchFormattedAddress(address, licensekey, recordcount, threshold, coordsys); }
Input parametersThe input parameters are defined as follows: addressesThe addresses parameter needs to contain an array of addresses in the following format:
where add1 is an address variable. e.g.
Licence KeyThe licencekey parameter must contain a valid licence key which is emailed to you on registration. If you have forgotten your key you may find it by logging on to the isharemaps.com website and clicking on Profile in the USER MENU. Record CountThe recordcount must always be "1" when geocoding. ThresholdThis threshold should be the geocode percentage below which you do not wish to return results e.g. 0.85. If the geocode score falls below this threshold the returned results will be blank. Co-ordinate SystemThis coordsys parameter represents the co-ordinates system that you wish to use. The valid entries are 0=British National Grid and 1=Longitude & Latitude - WGS84. Results The results are passed back in a results array. The following is some sample javascript showing how to handle the results. if (result == null) { alert("It appears that your licence key is invalid"); } else { // alert('Array Length: ' + result.length); var searchResultArea = document.getElementById("searchResultArea"); var sMessage = ""; //Show all the arrays for (i=0; i<result.length; ++i) { sMessage += 'Array No: ' + (i+1) + '\n<br>'; sMessage += 'Entity Name: ' + result[i]['EntityName'] + '\n<br>'; sMessage += 'x: ' + result[i]['x'] + '\n<br>'; sMessage += 'y: ' + result[i]['y'] + '\n<br>'; sMessage += 'score: ' + result[i]['score']; (sMessage); // display search results // alert(sMessage); searchResultArea.innerHTML += "<div class=\'searchResult\'>" + sMessage + "</div>"; sMessage = ""; } }
The results array is defined as follows: Entity NameEntityName contains the location result’s entity name (display name). Xx is the longitude or British National Grid X co-ordinate, depending on co-ordinate system used. Yy is the latitude or British National Grid Y co-ordinate, depending on co-ordinate system used. ScoreThe score represents the geocode matching score and is composed of a letter (A-C) followed by a percentage score e.g. A0.nn. The higher the score, the more accurate the result. The letter scores have the following meaning:
ExampleInput add1 = new atAddress("","","","KT19 8LN", "") Results Array No: 1 Entity Name: KT19 8LN
FilesDownload the whole javascript sample file here. |
|||||||||
| < Prev |
|---|


