Forum Discussion
_anomDiebolt_
7 years agoQrew Elite
This is trivial to do although I would suggest you don't use a webhook - just use script from your form. There is no point in making it more complicated by implementing it through a webhook.
Here is the code that takes QuickBase HQ's (150 Cambridgepark Dr, Cambridge, MA 02140) three word identifier (puns.chew.snow) and gets the JSON response and in particular the lat, lon and map url:
Here is the console output:
And if you don't want to use jQuery here is the equivalent code using the Fetch API:
Here is the code that takes QuickBase HQ's (150 Cambridgepark Dr, Cambridge, MA 02140) three word identifier (puns.chew.snow) and gets the JSON response and in particular the lat, lon and map url:
var apikey = "YOUR API KEY";
var addr = "puns.chew.snow";
var url = 'https://api.what3words.com/v2/forward?addr=${addr}&display=full&format=json&key=${apikey...;
$.get(url)
.then(function(json) {
console.log(json.geometry.lat);
console.log(json.geometry.lng);
console.log(json.map);
console.log(JSON.stringify(json, null, " "));
});
Here is the console output:
42.394445
-71.146089
http://w3w.co/puns.chew.snow
{
"thanks": "Thanks from all of us at index.home.raft for using a what3words API",
"crs": {
"type": "link",
"properties": {
"href": "http://spatialreference.org/ref/epsg/4326/ogcwkt/";,
"type": "ogcwkt"
}
},
"words": "puns.chew.snow",
"bounds": {
"southwest": {
"lng": -71.146107,
"lat": 42.394432
},
"northeast": {
"lng": -71.146071,
"lat": 42.394459
}
},
"geometry": {
"lng": -71.146089,
"lat": 42.394445
},
"language": "en",
"map": "http://w3w.co/puns.chew.snow";,
"status": {
"reason": "OK",
"status": 200
}
}
And if you don't want to use jQuery here is the equivalent code using the Fetch API:
fetch(url)You can test this code from the console and then implement it using the IOL technique. Instead of logging the lat/lon you would just fill in a form value using code similar to this:
.then(res => res.json())
.then((json) => {
console.log(json.geometry.lat);
console.log(json.geometry.lng);
console.log(json.map);
console.log(JSON.stringify(json, null, " "));
});
_fid_7.value = json.geometry.lat;
_fid_8.value = json.geometry.lng;
_fid_9.value = json.map;