Notifications

260 views

Description


 

Google have changed their model where Client ID is only available for old Google Maps business plan holders and new Premium Plan holders (Client ID's start with "gme-"). Any new Google plan holder will likely use the API Map Key as Client ID is not available.

When an instance is configured to use an API Map key instead of a Client ID for Google Maps functionality, Google Map functions work within the instance except for the Geocoding Latitude and Longitude functionality which fails. This is because the Google request to obtain the Latitude and Longitude only caters for Client ID and not API Map Key. 

 

Ref: https://docs.servicenow.com/bundle/london-platform-user-interface/page/administer/navigation-and-ui/concept/c_MapPages.html#d27634e322

Ref: https://developers.google.com/maps/documentation/javascript/get-api-key#client-id

 

Steps to Reproduce


 

To enable Latitude and Longitude functionality in the instance:

  • Configure the "Table used by the map": /system_properties_ui.do?sysparm_title=Google%20Maps%20Properties&sysparm_category=Google%20Maps (NOTE: Default is "cmn_location")
  • Enable the associated "get_lat_long" business rule.
  • Enable the scheduled job "Process Geocoding Request"
  • Go the location table (cmn_location)
  • Update an address of a location record (Street or City or State or ZIP or Country)
  • System logs will show the following error when attempting to update Latitude and Longitude.

*** Script [GoogleMapsHelper.google_getLatLong]: Unknown response: Unable to authenticate the request. Provided 'signature' is not valid for the provided client ID, or the provided 'client' is not valid.

 

Workaround


 

The script include "GoogleMapsHelper" and function "google_get_LatLong" constructs the URL request made to Google to obtain the Latitude and Longitude of the address.  

 

var geo_auto = "google.maps.geocoding.automation";

var gl = new GSLog("google.maps.logging", "GoogleMapsHelper.google_getLatLong");
var url = "https://maps.googleapis.com/maps/api/geocode/json";
var query = "address=" + addr + "&sensor=false&client=" + gs.getProperty("google.maps.client");
var parms = new String(query).replaceAll(" ", "+");
var url_to_sign = "/maps/api/geocode/json?" + parms;

gl.logDebug("signing url: " + url_to_sign);
var signature = GoogleMaps.generateSignature(url_to_sign);
gl.logDebug("signature: " + signature);

parms += "&signature=" + signature;

The construction of the request URL is only for Client ID and doesn't cater for the API Map Key.

https://maps.googleapis.com/maps/api/geocode/json?address=<ADDRESS>&sensor=false&client=<CLIENT ID>&signature=<SIGNATURE>


The URL to make a request to Google using the API Map Key is:

https://maps.googleapis.com/maps/api/geocode/json?address=<ADDRESS>&sensor=false&key=<API Key>

 

For API Map Keys to work, update the following lines in the "GoogleMapsHelper" script include.

Line: 17

Before: var query = "address=" + addr + "&sensor=false&client=" + gs.getProperty("google.maps.client");
After: var query = "address=" + addr + "&sensor=false&key=" + gs.getProperty("google.maps.key");

 

Line: 26

Before: parms += "&signature=" + signature;
After: //parms += "&signature=" + signature;

This will now use the API Map Key for geocoding requests.

 

Article Information

Last Updated:2019-05-21 11:50:44
Published:2019-01-21