Hello @photodolphin
The Developer version of the plugin is distributed with “DISTANCE” operations module that includes the DISTANCE operation, it is able to determine the distance between two addresses using the Google Maps API. Please, visit the following link:
https://cff.dwbooster.com/documentation#distance-module
Best regards.
What if I wanted to use my own JS code without Goolge API? Your free version says I can but it is not working.
<script src=”https://cdn.jsdelivr.net/npm/graphhopper-js-api-client/dist/graphhopper-client.js”></script>
<script>
window.onload = function() {
var ghRouting = new GraphHopper.Routing({
key: “my key”,
vehicle: “car”,
elevation: false
});
ghRouting.addPoint(new GHInput(47.400905, 8.534317));
ghRouting.addPoint(new GHInput(47.394108, 8.538265));
ghRouting.doRequest()
.then(function(json) {
return json
console.log(json);
})
.catch(function(err) {
console.error(err.message);
});
};
</script>
I know function below is working because it prepends distance value to top of the page if i click Preview button. But how do I assign it to fieldname?
Wherever I put “return” as described in
https://wordpress.dwbooster.com/includes/calculated-field/equations.html
does not work. Please help!
(function(){
$(document).ready(function(){
$.getJSON("https://graphhopper.com/api/1/matrix?point=40.67472,-73.39333&point=40.762,%20-73.523&type=json&vehicle=truck&debug=true&out_array=distances&key=MyKey", function(result){
$.each(result, function(i, field){
$("body").prepend(field[0]);
});
});
});
})();
Hello @photodolphin
First, I recommend you to call the code from a “HTML Content” field, using the showHideDepEvent event (that ensures the form has been generated)
<script>
fbuilderjQuery(document).one('showHideDepEvent', function(){
var $ = fbuilderjQuery;
$.getJSON("https://graphhopper.com/api/1/matrix?point=40.67472,-73.39333&point=40.762,%20-73.523&type=json&vehicle=truck&debug=true&out_array=distances&key=MyKey", function(result){
$.each(result, function(i, field){
$('[if*="fieldname1_"]').val(field[0]);
});
</script>
Furthermore, pay attention in the way I’m assigning the returned value to a hypothetical field in the form with name fieldname1, so, you should to use this code to assign the value to your real field.
I’m sorry, but this code is specific to your project, if you need additional support implementing your project, you should request a custom coding service through my private website:
https://cff.dwbooster.com/customization
Best regards.