> It seems this function was called after the rest of all the code.
> Why?
Because it is asynchronous.
geocoder.geocode( {'address': address}, function( ... ) { ... }
only sends a request to Google. The callback function is NOT run at
this time.
The browser then carries on and executes the code that follows.
For example
geocoder.geocode( {'address': address}, function( ... ) { ... }
alert ('banana');
the alert will display BEFORE the results get back from Google.
Sometime later, the results come back and the callback function will
be run.
In the case of your code snippet, your callback refers to variables
'map' and 'addr' and 'userPosition' that may or may not be within the
scope of the callback function when it runs, you need to be careful
about that.