Q:

Change local variable inside method, when the method is executed the variable is not changed

I'm working on an android app. I have this form, when the button is clicked it execute a method called insertData(). Inside this function I change a local variable called "address" with another function getAddress().
Inside the function getAddress the local variable "address" is changed successfully. But when we enter the function insertData(), the variable "address" still contains the old data in this case "Location Unknown".
What am I not seeing here?
insertData()
public String address = "Location unknown";

public boolean insertData(String title, String description, String image, Double longitude, Double latitude, String date) {
    String location = Double.toString(longitude) + "," + Double.toString(latitude);
    getAddress(location);
    Log.d("TAG2", address); // Still "Location unknown"
    SQLiteDatabase db = this.getWritableDatabase();
    ContentValues contentValues = new ContentValues();
    contentValues.put(COL_2, title);
    contentValues.put(COL_3, description);
    contentValues.put(COL_4, image);
    contentValues.put(COL_5, longitude);
    contentValues.put(COL_6, latitude);
    contentValues.put(COL_7, date);
    contentValues.put(COL_8, address);
    long result = db.insert(TABLE_NAME, null, contentValues);
    if (result == -1)
        return false;
    else
        return true;

}

getAddress()
    public void getAddress(String coordination) {

    String token = "{removed for a reason haha}";
    String url = "https://api.mapbox.com/geocoding/v5/mapbox.places/" + coordination + ".json?access_token=" + token;

    OkHttpClient client = new OkHttpClient();

    Request request = new Request.Builder().url(url).build();

    client.newCall(request).enqueue(new Callback() {
        @Override
        public void onFailure(Call call, IOException e) {
            e.printStackTrace();
        }

        @Override
        public void onResponse(Call call, Response response) throws IOException {
            if(response.isSuccessful()) {
                String data = response.body().string();
                JsonParser parser = new JsonParser();

                try {
                    JsonObject obj = (JsonObject) parser.parse(data);
                    JsonArray arr = obj.getAsJsonArray("features");
                    JsonObject objj = arr.get(2).getAsJsonObject();
                    String place = objj.get("place_name").getAsString();
                        address = place;
                        Log.d("TAG", address); // Gives an address
                    }
                    catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }
        });
    }

Logcat Debugger
2019-06-15 20:12:58.968 31465-31465/com.example.triptracker D/TAG2: Location unkown
2019-06-15 20:12:59.269 31465-31569/com.example.triptracker D/TAG: Mountain View, California, United States

I cannot change the onResponse() method to return String. I don't know why, but it is a read only method.
getAddress {changed}
    public void getAddress(String coordination) {

    String token = "{empty}";
    String url = "https://api.mapbox.com/geocoding/v5/mapbox.places/" + coordination + ".json?access_token=" + token;

    OkHttpClient client = new OkHttpClient();

    Request request = new Request.Builder().url(url).build();

    try (Response response = client.newCall(request).execute()) {
        String data = response.body().string();
        JsonParser parser = new JsonParser();

        if (!response.isSuccessful()) throw new IOException("Unexpected code " + response);

        JsonObject obj = (JsonObject) parser.parse(data);
        JsonArray arr = obj.getAsJsonArray("features");
        JsonObject objj = arr.get(2).getAsJsonObject();
        String place = objj.get("place_name").getAsString();
        address = place;
        Log.d("TAG", address);
    }
    catch (Exception e) {
        e.printStackTrace();
    }
}

A:

getAddress() does its work asynchronously. By the time getAddress() returns, your HTTP request will not be complete, and so address will not have changed yet. 
Since insertData() is doing disk I/O, you should be calling insertData() on its own background thread, so you do not freeze the UI while the disk I/O is going on. If that is the case, then you can use OkHttp synchronously, using execute() instead of enqueue(). That will allow you to have getAddress() return the address, so you can insert it into your database.

