Zoho Flow custom function to get address from Google Maps geocoding
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
map addressToCoordinates(string addressString) | |
{ | |
/** | |
* This snippet: https://gist.github.com/cliffordp/068b32913ba25d1cd998507398c950c8 | |
* | |
* Get lat/long from Google. | |
* https://developers.google.com/maps/documentation/geocoding | |
* | |
* CRM limits Decimal Fields to 9 digits, which is sufficient: | |
* https://rapidlasso.com/2019/05/06/how-many-decimal-digits-for-storing-longitude-latitude/ | |
* | |
* Deluge has its own available but may not be as accurate: | |
* https://www.zoho.com/deluge/help/map-tasks/geocode.html | |
*/ | |
geoUrl = 'https://maps.googleapis.com/maps/api/geocode/json?key=___YOUR_API_KEY___®ion=us&bounds=' + zoho.encryption.urlencode('37.169071,-100.206985|33.385586,-93.966751') + '&address=' + zoho.encryption.urlencode(addressString); | |
// https://www.zoho.com/deluge/help/webhook/invokeurl-api-task.html | |
response = invokeurl | |
[ | |
url :geoUrl | |
type :POST | |
]; | |
//info response; | |
valueMap = Map(); | |
if('OK' == response.get('status')) | |
{ | |
results = response.get('results').toCollection(); | |
valueMap.put('resFormattedAddress',replaceFirst(results.get('formatted_address'),', USA','')); | |
valueMap.put('resLat',round(results.get('geometry').get('location').get('lat').toDecimal(),9)); | |
valueMap.put('resLng',round(results.get('geometry').get('location').get('lng').toDecimal(),9)); | |
} | |
// In Zoho Flow, do something like this: ${addressToCoordinates.resFormattedAddress} | |
return valueMap; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment