Call EasyTerritory Geocoding REST Service


Overview

The EasyTerritory Geocoding Service will covert street addresses to their latitude/longitude equivalents.  Having the latitudes and longitudes of records makes it possible to place those records on a map.  In order to use this powerful feature, a Bing Maps key will be needed.  You can get a free Dev. test key here: www.bingmapsportal.com.

Please follow these steps to call the Geocoding Service:

  • – Get a login token by calling the EasyTerritory login web service:
  • – Set the http request cookie with the login token and use the request.Method = “POST” to the EasyTerritory Geocode service:
    https://apps.easyterritory.com/{yourGuidhere}/APP/REST/Geocode
  • – Set the request.ContentType = “application/json”.
  • -The json object to post for geocoding:
    { 
        keyCustomer: string; //any unique identifier
        keyBing: string; //your bing key
        defaultCountryCode: string;
        enableAddressFallback: boolean;
        addressList: string[],
     }
     

    *Note: keyCustomer is just a unique id (e.g. GUID) for use in caching and customer tracking (it can be any unique value).

  • – Code Sample:
     document.cookie= "oitoken=EztToken"; 
        
    	$.ajax({
        	url: "https:/apps.easyterritory.com/{yourGuid}/app/REST/Geocode",
         	type: "POST",     
         	contentType: "application/json",
         	data: JSON.stringify( {
    			"keyCustomer":"{Your Unique Identifier}",
    			"keyBing": "{Your Bing Key}", 
    			"addressList": "{addresses to be geocoded}"
     		}),
         	xhrFields: {
               withCredentials: true                                 }
    	});
    

     

    *Note: This will not work in a client-side scenario if you attempt to go cross-domain. Cross domain situations require a server side proxy using C#.

  • – The return json object:
    	 {
       results: iGeocodeResult[];
       rowCount: number;
       hasRowErrors: boolean;
       error: string;
     }
    
  • – Interface IGeocodeResult
    {
       addressStandardized: string;
       addressCorrected: string;
       addressLine: string;
       country: string;
       adminLevel1: string;
       adminLevel2: string;
       locality: string;
       postalCode: string;
       locationMerc: { x: number, y: number };
       location: { lon: number, lat: number };
       finalProvider: string;
       didFallback: boolean;
       quality: eGeocodeQuality;
       qualityString: string;
       timeStampUtc: number;
       msToComplete: number;
       warning: string;
     }