As Adam pointed out, you're trying to use the url
variable before it gets assigned a value (other than the 'BB'
you initialize it with).
Unless you have a good reason to make the url
variable global and understand the issues around asynchronous code, it is best if you do not declare this variable outside the callback. This leads to the kind of trouble you ran into.
Instead, declare url
right where you assign it, inside the callback. And then do whatever you need to do with it inside the callback, or in a function you call from inside the callback. Do not attempt to use it as a global variable.
For example, this would work without having the problem you ran into:
navigator.geolocation.getCurrentPosition(function (position) {
var url = 'http://maps.googleapis.com/maps/api/geocode/json?latlng=' + position.coords.latitude.toString() + ',' + position.coords.longitude.toString();
console.log(url);
});