I have been trying to return the value of 'city' variable but i keep geeting weird results, i know there must be something wrong with my code, i hope you can help me figure out what it is.
function getCity(lat,lng)
{
var url="http://maps.googleapis.com/maps/api/geocode/json?latlng=";
var sensor="&sensor=false";
var city;
$.getJSON(url+lat+","+lng+sensor,function(json)
{
var address=json.results[0].address_components;
var addr;
for(var i in address)
{
addr=address[i];
if(addr.types[0] == "locality" && addr.types[1] == "political")
{
city=addr.long_name;
}
}
});
return city;
}
return city. I think it should readcity = addr.long_name- you're missing the=.console.log(city);next tocity=addr.long_name;and i get the correct value.