GeoCode Plugin using Google Maps or BING Maps

Overview:

In my previous post, I talked about building a Custom Workflow Activity that works for CRM 2011 Online and CRM 2011 On-Premise. Now decided to build a geocoding plugin which will do the same, except it is like Turbo the snail. Designed it in such a way, you can make this to work for any Entity, OOB or Custom and for any number. Any secrets, naaaahhhhh. Just plain old CRM. That’s what I like about CRM. It is LEGO blocks. No end to creativity. Created a config entity to hold all config data, be it Google Maps or Bing Maps. Ok, enough of the blah, blah, blah. Just get to the meat will ya. I felt there might be a need to goecoding to be synchronous, rather than a workflow. Well with 2013, that will change with Realtime Workflows.

Solution:

In this post I will deal with deploying, customizing and seeing the results of the plugin executing. Will post the source code online at Codeplex(https://crmmaps.codeplex.com/) when I make myself a bit free. Will provide a managed solution with just the plugin and config entity.

Step 1: Import Maps Solution.

Once you import the solution, you should see a new Group on sitemap under settings called E31 Maps. This will give you access to Geocode Config entity.

Step 2: Geocode Config Entity entries

In this step, I’m assuming you are adding a record to geocode an address in Account entity.

Entity Name = account(this is the logical name, not schema name of the entity).

Keeping with the above guideline, please fill in the names of the fields that are the key players in the geocoding process.

Inputs:

  • Entity Name
  • Bing Maps Key ( can be empty when using google maps url)
  • Bing Maps Url, or Google Maps Url
  • Street Field(name of the field in contact entity which hold the Street Address value)
  • City Field (name of the field in contact entity which hold the City value )
  • State Field (name of the field in contact entity that holds the State or Province value)
  • Postal Code Field (name of the field in the contact entity that holds ZIP code value)
  • Country Field

Outputs:

  • Latitude Field (name of the field that will hold geocoded Latitude value in contact entity)
  • Longitude Field (name of the field that will hold the geocoded Longitude value in contact entity).

Example of screenshot for Account entity:

GeocodeConfig_Account_Bing

Geocode Config record values for geocoding Account entity using BING Maps

Step 3a: Plugin Registration – New Step for CREATE

Once the Plugin is registered as part of the installation of the managed solution, fire up the Plugin registration tool supplied with 2011 SDK. Create a new STEP for this assembly as shown below.

Bing_Create_Account

STEP Configuration settings for Account CREATE Message

Step 3b: Plugin Registration – New Step for UPDATE

Want to finish the configuration for the UPDATE message so that you can go ahead and fire up the plugins by creating accounts or updating accounts.

  1. Create a new STEP for the assembly for the UPDATE message,
  2. In the Step Configuration section, please select the Filtering attributes to be Input attributes as mentioned in the previous section. The 5 attributes are a) Street, b) City, c) State, d) Zip and e) Country.
  3. Fill in other parts of the Step configuration screen as shown below.

    Bing_Update_Account

    STEP Configuration settings for Account UPDATE Message

  4. Create a PreImage for the UPDATE message step. It is important that I know the records previous address information before the change occurred. Set up the PreImage for these 5 fields. Mainly the ones that you need to compare with the changed values. These fields are picked from the entity for which you registered UPDATE step for. In our case we are dealing with Account. Select these 5 fields only for the PreImage address1_city, address1_country, address1_stateorprovince, address1_line1, address1_postalcode
    Bing_Update_Account_PreImage

    PreImage Setting for Account UPDATE step.

    There you go. You are done. Way the geocoding works is pretty simple. For a Create message, no need for any explanation. I pass in values that are available to the BING Maps geocode api. Bing maps returns a result and result quality(next release). For the Update operation, it is little bit tricky. CRM will send only the fields that changes to the event. In the case for fields that have not changed I get the value from PreImage. then I do the usual processing in passing all values that are parts of the address to the geocode API. Viola. I tested with CRM Online and works. Now you need to tell me if there are other features that must be added to this and if it is performing well.

NOTE: It is up to you as a developer to register the appropriate STEPS for the respective Geocode API, if it is BING or GOOGLE. This article is primarily is focused on BING Maps API. I’m working on a release of the plugin that uses Google Maps API. Both plugins will make use of Geocode Config entity to decide where the address fields are in the entity record in question.

As always comments are welcome. enjoy!

Download Solution : https://crmmaps.codeplex.com/

Prabhakar