Update Geolocation Background Task

Find Background Tasks here:

M:\NWS\Titan\CustomBackgroundTasks

Find the Geocoding Folder and drop it into your project.

Installation/Configuration

This assumes that there is an existing, configured BackgroundService solution for this instance.

GeoLocation service API Key

It is suggested that a unique API Key be used for each client instance. If an API Key for this client doesn’t already exist (may be used for other GeoLocation needs such as DataList proximity search), then you will need to get one. Here are the instructions to get a new API key for the following service providers:

Bing

https://msdn.microsoft.com/en-us/library/ff428642.aspx

Google

https://developers.google.com/maps/documentation/geocoding/

Titan

  • Add the following fields to the Schema that contains the Address and GeoCode data. You may choose any name for the fields as they are configurable in the ConfigSettings.
    • Geo_Coordinates [type=Geographic Coordinate] – the field containing Lat/Long values
    • (*) Geo_Error [type=Text Area] – will be populated with any error that occurs while processing the record. Any record that contains a value here will not be selected for processing.
    • (*) Geo_Confidence[type=Text(1line)] – will be populated with the “confidence” rating from the API. This is different for each API and conveys how confident that it located the exact address.

(*) – these fields are optional

SDK

This assumes that this will be implemented as a CustomBackgroundTask in each instance that it is used. Future enhancement may make this a generic “plug and play” utility.

  • Add the following files to the “BackgroundService.CustomBackgroundTasks” project for the corresponding client
    • Install_UpdateGeoCoordinates.sql – contains SQL commands for the DB
    • UpdateGeoCoordinatesTask.cs – the custom Background Task
    • GeocodingSupport.cs – library containing supporting methods
  • Modify “Install_UpdateGeoCoordinates.sql” and update the DefaultConfigArgs with the appropriate configuration.
    • Also change the last line to the appropriate Titan user account
      • GRANT EXECUTE ON custom_GeoCode_GetRecordsForUpdate TO cmsDHIUser
    • Modify the following optional fields if desired/needed (see sample XML at the end of this document)
      • ErrorField – If the Geo_Error field was added to the schema above, configure the field name here
      • GeoConfidenceField – If the Geo_Confidence field was added to the schema above, configure the field name here
      • ThrottleInMilliseconds – Set a delay between each API call (in milliseconds)
      • SPROCToCallAfterProcessing – Call a sproc after all the records have been processed (i.e. to populate another table, etc)
  • In the CustomBackgroundTasks project, add a Reference to the following files. If a file doesn’t exist there, you will need to add it first (thank you Captain Obvious).
    • “Dependencies/App/CmsWkstDisplay.dll”
    • “Dependencies/Web/UISupport.dll”
    • Also add reference to “System.Web” assembly

DB

  • Run “Install_UpdateGeoCoordinates.sql”. This will insert the new Background Task with configs and create the required SPROCS

Titan (again)

  • Under “Scheduled Jobs”, select the new “Update Geo Coordinates” job and click the “+” sign to add a new instance:

scheduled job

Sample ConfigArgs XML with Optional Fields

 

<ConfigArgs>

<DataSiteDocId>74</DataSiteDocId>

<SearchString>

<Field name="Dealer_Address" required="true"/>

<Field name="Dealer_City" required="true" appendAfter=","/>

<Field name="Dealer_State" required="true"/>

<Field name="Dealer_Zip" required="true"/>

<Field name="Dealer_Country" required="true"/>

</SearchString>

<GeoField>Dealer_Coordinates</GeoField>

<ErrorField>Geo_Error</ErrorField>

<GeoConfidenceField>Geo_Confidence</GeoConfidenceField>

<ThrottleInMilliseconds>800</ThrottleInMilliseconds>

<NumberOfRecordsToProcess>10000</NumberOfRecordsToProcess>

<SPROCToCallAfterProcessing>

usp_chw_UpdatePrimaryProviderData

</SPROCToCallAfterProcessing>

<Geocoder>

<Name>Google Maps Geocoder</Name>

<Class>NorthwoodsSoftwareDevelopment.Cms.CustomBackgroundTasks.GoogleMapsGeocoder, CustomBackgroundTasks</Class>

<Parameters>

<APIKey>AIzaSyA7m2S8fK0fUgeKGUWFTztlyykoktO_mo0</APIKey>

</Parameters>

</Geocoder>

</ConfigArgs>

Please wait while we gather your results.
top