- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-02-2016 07:59 AM
I'm very interested in using the Mapping Reports in Helsinki, and to do that it looks like I need to populate the longitude / latitude fields for records on my Locations and Companies tables. I read here that there are Business Rules (both named get_lat_long) for these tables that will populate these fields automatically based on the address information on each record. I then read here that you need an API key from Google in order to use this feature now. I've turned on the two business rules, obtained a Google Maps API key, entered it in the "Private key for Google Maps API for Business" under System Properties -> Google Maps, and am still having no luck. When I update location records no lat / long information seems to be pulled in. Could anyone offer me some guidance as to what I'm missing? The problem appears to be on the SN instance side as the Google API dashboard doesn't show any traffic.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-21-2016 07:33 AM
Finally got this to work. Posting the new business rule I ended up using in case anyone else is having an issue with the OOB methods. Disclaimer: I'm not really a coder, I put this together using what I found in the community and the OOB BRs / script includes, so this may not conform to coding best practices.
var street = new String(current.street);
street = street.replaceAll("\r","");
street = street.replaceAll("\n"," ");
street = street.replaceAll(" ","+");
var city = new String(current.city).replaceAll(" ","+");
var state = new String(current.state).replaceAll(" ","+");
var zip = new String(current.zip).replaceAll(" ","+");
var address = "address=" + street + "," + city + "," + state + "," + zip + "&key=YOURGOOGLEAPIKEY";
var ws = new HTTPAdaptor("https://maps.googleapis.com/maps/api/geocode/json?");
var ret = ws.doGet(address);
var lat = 0,
lng = 0;
try {
var output = new JSONParser().parse(ret);
if (output.status == "OK") {
lat = output['results'][0]['geometry']['location']['lat'];
lng = output['results'][0]['geometry']['location']['lng'];
current.latitude = lat;
current.longitude = lng;
current.update();
} else {
gs.logErr("Get_Lat_Long Lookup Error: " + output.status);
gs.logErr("Address: " + address);
gs.logErr("API Response: " + ret);
}
} catch (err) {
gs.logErr("Geocoding error: " + jsonOutput);
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-02-2021 08:58 AM
Update: after some time it stopped working. Kind of expected 😄
I took it as a trigger to reimplement it the new way. You can find the post on it here.