Quantcast
Viewing latest article 6
Browse Latest Browse All 229

Implementing a Geocoder for Google Maps in SAP CRM

One important aspect and target of a good Customer Relationship Management system is to manage acurate customer address and contact information. SAP integrates a framework in SAP CRM to gather and store geolocation information about a customer's location, i. e. the latitude and longitude of an address. This is especially critical in scenarios where the exact customer location is required (i. e. for weather information services).

You as a customer can enhance the framework and hook your own geocoding service into it. By standard the geocoding service in SAP CRM determines the geocoordinates based on country and region when an address is saved. Of course for most of the use cases, this is much too unprecise.

 

In this blog I describe how to use Google Maps as geocoding service in SAP CRM.

 

The Geocoding API in Google Maps is an HTTP based API where you can pass in an address and get geographical coordinates in return:

 

https://maps.googleapis.com/maps/api/geocode/xml?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&key=YOUR_API_KEY

 

Check out the API documentation for more details.

 

To integrate the Google Maps API in SAP CRM, start by creating a Geocoder class. That is a generic ABAP class implementing interface IF_GEOCODING_TOOL. Activate the class only now, it will be implemented later.

Image may be NSFW.
Clik here to view.
Image_01.png

 

This class must be registered in customizing (SPRO: SAP NetWeaver -> General settings -> Set Geocoding) as geocoder source.

Image may be NSFW.
Clik here to view.
Image_02.png

 

Next step is to assign the relevant address field to the new geocoder source.

Image may be NSFW.
Clik here to view.
Image_03.png

 

As the quality of geocoding solutions might vary between countries, you can define a geocoder per country. Here I defined the Google API for German addresses only.

Image may be NSFW.
Clik here to view.
Image_04.png

 

Now let's implement the geocoder class and method GEOCODE of interface IF_GEOCODING_TOOL. It is called everytime an address is updated in CRM.

The methods gets a table with addresses and some other information. It should geocode each of the addresses and put the results (latitude and longitude) in the CONTAINERS parameter.

Image may be NSFW.
Clik here to view.
Image_05.png

 

The custom submethod GEOCODE_ADDRESS invokes another custom class that calls the Google Maps Geocoding API.

Image may be NSFW.
Clik here to view.
Image_06.png

 

The Geocoding API is an HTTP-based web service API where this class sends GET requests to and consums the result.

Image may be NSFW.
Clik here to view.
Image_07.png

 

The request URL is created by simply concatenating the base URL and the current address. Please note that a response in XML is requested.

Image may be NSFW.
Clik here to view.
Image_08.png

 

SAP offers an XML library called iXML to read and parse XML content (see SAP help here). I haven't found a similar version for JSON with the same capabilities.

Image may be NSFW.
Clik here to view.
Image_09.png

 

Now if you're create an account and maintain a German address, our Google Maps geocoder is called and the Geocoding API is asked for the coordinates.

Image may be NSFW.
Clik here to view.
Image_11.png

 

The geograhical coordinates are stored in table GEOLOC.

Image may be NSFW.
Clik here to view.
Image_12.png

 

Please share your comments and thoughts. I would really appreciate your feedback.


Viewing latest article 6
Browse Latest Browse All 229

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>