Meteor.call from inside google api get callback

Hi,
I have this Meteor.http call to google api on one event:
var url = “https://maps.googleapis.com/maps/api/geocode/json?address=” + street + " " + city+ “&key=AIzaSyCBpwwwwwwwwwwwwwww”;
Meteor.http.get(url, {}, function (err, results) {

   //a Meteor.call

})

It works for it self. but when I try to insert into it, a Meteor call, which also works fine for it self, out side that callback:
Meteor.call(‘setLocation’, this._id, this.createdBy, location, function(error, result){
if(error){
console.log(error);
}else{
}
});

I get this match error:
errorClass {message: “Match error: Expected string, got undefined”, path: “”

It’s exactly the same call and method that runs well outside the callback.

So what’s the right way to handle this? how to do a Meteor call from with in a google api call back?
Thanks,
Avi.

Is this Http request on the server?

i yes, you must use the http call sync not async on the server, the respond from the http call you can acces on the client

Thanks,
no it’s on the client.

Without seeing more code outside of this snippet, the following jumps out at me:

Meteor.call('setLocation', this._id, this.createdBy, location, function(error, result) {

this._id and this.createdBy are not scoped to the enclosing context and will be undefined. Also, location may or may not be defined (it depends what’s happening before this call).

Thanks, I don’t understand what you mean by location may or may not, this meteor call supposed to be executed from the success call back?

I have no visibility of where location is set, so I don’t know whether it will be defined or not. If you share more of the surrounding code, including where that variable comes from that may help.

Also, please surround your code blocks with triple backticks:

```
code here
```

Sorry, I thought i’ve passed that part of the code.
Any way, yes it was the ‘this’ context problem.
thanks.