0

I have a form in jotform that its going through zapier to [spatula.io][1] and everything was working fine until this error started happening:

TypeError: Cannot read property 'geometry' of undefined eval (eval at <anonymous> (/var/task/index.js:52:23), <anonymous>:47:39) process._tickDomainCallback (internal/process/next_tick.js:135:7)

I know it has to do with Google API but i can't figure why or whats wrong. Thank You.

output = [{id: 123, hello: "world"}];var key = 'AIzaSyBSgUahDolVIFG3q4ogCZMOBoyZXTW78UM ';
var address = {};

input.address.split(/[\n\r]+/).forEach(function(line) {
    var parts = line.split(': ');
    address[parts[0].toLowerCase().replace(/\s+/g, '')] = parts[1];
});

var __x = {
    streetname: 'Maple Avenue',
    housenumber: '746',
    city: 'Glenside',
    state: 'PA',
    postalcode: '19038'
};

var formattedAddress = [
    address.housenumber,
    address.streetname,
    address.city,
    address.state,
    address.postalcode
].join(' ');

fetch(
    'https://maps.googleapis.com/maps/api/geocode/json?key=' +
        key +
        '&address=' +
        encodeURIComponent(formattedAddress)
)
.then(function(res) {
    return res.json();
})
.then(function(body) {
    callback(null, {
        address: formattedAddress,
        geocodeResult: body.results[0].geometry.location
    });
})
.catch(callback);
  • It's impossible to help you when we can't see the code. However, it looks like there's a variable that your code is trying to access that isn't defined. It looks like you want to access `object.geometry` but `object` is `undefined`. See: https://stackoverflow.com/questions/8004617/javascript-cannot-read-property-bar-of-undefined?lq=1 – M - May 22 '18 at 19:58
  • eval (eval at (/var/task/index.js:52:23), :47:39) process._tickDomainCallback (internal/process/next_tick.js:135:7) – Max Reynoso May 22 '18 at 20:01
  • I'm trying to add the code but it won't let me. I'm sorry i'm new to this and learning as i got but i appreciate the help big time! – Max Reynoso May 22 '18 at 20:07
  • I don't mean we need to see the error message you're getting. I mean, we need to see the code you've written that leads to this error message. See how to write a [minimal, complete, and verifiable example](https://stackoverflow.com/help/mcve). – M - May 22 '18 at 20:09
  • ok i figured out how to add the code to the question. – Max Reynoso May 22 '18 at 20:18
  • I believe it might be that `body.results[0]` is empty, so when it tries to access `body.results[0].geometry`, there is no data to read there. Any way you could do `console.log(body)` before the `callback(null, {...})` to see what it contains? – M - May 22 '18 at 20:28
  • yep! look at the input to the zap and see if that causes a maps response without any results. If that's the case, check for `if (body.results.length)` in your last promise. If it's there, return the first item. If it's not, return nothing (and make sure downstream actions have a filter or something so they don't fire without input) – xavdid May 22 '18 at 23:32

0 Answers0