I am using the code below to retrieve the latitude and longitude of a given location if the value has been changed for each div containing the class `.event`.

The problem I'm having is that only two outcomes occur from this code:

* The values returned from one JSON request are used for every `lat` and `lon` variable
* The variables `lat` and `lon` remain exactly the same, as if they were remain untouched so the JSON values are not replaced.

Below is the code I am using:

```
    $(".button").click(function(){

            data = "";
            $(".event").each(function(){

                original = $(this).find(".address").data("original");
                location = $(this).find(".address").html();
                lat = $(this).find(".lat").html();
                lon = $(this).find(".lon").html();

                if (original !== location) {

                    $.getJSON( "http://nominatim.openstreetmap.org/search?q="+location+"&format=json&polygon=1&addressdetails=1", function(result) {
                        lat = result[0].lat;
                        lon = result[0].lon;
                    });

                }

                data = data + randomNumber() + ": " + lat + " " + lon + ",";

            });

            $(".data").val(data);
            $(".form").submit();

    });

```

The variable `data` will contain the `lat` and `lon` for each div containing the class `event`. The values will remain the same unless the address has been changed by the user, at which point they will be retrieved again via a JSON request. 

The form should then be submitted.

How could I fix this? Thank you