Step 1: Navigate to "REST Message" > New
Name = Get Lat Long
Endpoint = https://www.geocode.farm/v3/xml/forward
Under section "HTTP Method", click "Default GET".
Under section "HTTP Query Parameters", enter the following information, save
name | value | order |
addr | ${addr} | 100 |
country | ${country} | 200 |
lang | ${lang} | 300 |
count | ${count} | 400 |
Step 2: Navigate to "Map Page" > New > Paste the script below
var gr = new GlideRecord('incident');
gr.addEncodedQuery("active=true^caller_id.cityISNOTEMPTY");
gr.query();
while( gr.next() )
{
// Add copied REST Message Script BELOW this line
var r = new sn_ws.RESTMessageV2('Get Lat Long', 'Default GET');
r.setStringParameterNoEscape('country', gr.caller_id.country);
r.setStringParameterNoEscape('addr', gr.caller_id.city);
r.setStringParameterNoEscape('count', '1');
r.setStringParameterNoEscape('lang', 'en');
//override authentication profile
//authentication type ='basic'/ 'oauth2'
//r.setAuthentication(authentication type, profile name);
var response = r.execute();
gs.info('c='+gr.caller_id.country+', city='+gr.caller_id.city+', '+response);
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
// Add copied REST Message script ABOVE this line
// Extract latitude and longitude values from REST Message response
var xmlDoc = new XMLDocument2();
xmlDoc.parseXML(responseBody);
var myLat= xmlDoc.getNodeText("//latitude");
var myLong= xmlDoc.getNodeText("//longitude");
// Plot each Requested for's location on a google map
var item = map.addItem(gr);
item.latitude = String(myLat);
item.longitude = String(myLong);
item.dialog_title = gr.getDisplayValue();
item.icon = "https://maps.google.com/mapfiles/ms/micons/yellow.png";
item.icon_width = "32";
item.icon_height = "32";
}