I wrote a simple function in which your city location is determined. However, I am wondering if there is a way to force the function to wait for the getJSON and then move to the next line of code? In the example, you will see that it shows "Alert 1" skips "Alert 2" and goes directly to "Alert 3" and then shows the "Alert 2". Thank you in advance.
Best regards, George
var Alpha;
function Location(){
alert(Alpha + " 1");
$.getJSON("http://freegeoip.net/json/?callback=?", function(location){
Alpha = location.city;
alert(Alpha + " 2");
});
alert(Alpha + " 3");
}
$(document).ready(function() {
Location();
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>