Theofilos Mouratidis
Theofilos Mouratidis

Reputation: 1156

Can't set a global variable within geocoding function

i got this function:

function myfunc()
{
    var x;
    geo.geocode({ 'latLng': marker.getPosition() }, function (results, status) {
    somestuff...
    x = what i need;
    });
    alert(x); //x undefined...
}

The geocoding function is working properly... How can I solve this problem??

Upvotes: 0

Views: 378

Answers (1)

fw42
fw42

Reputation: 32

I think the problem is that you set x inside a callback function. You set the callback and after that you call alert(), but the callback function might not have been executed at that point.

Upvotes: 1

Related Questions