How to find city name with latitude and longitude in javascript? : I already searched in a lot of websites for a solution but no one of them worked.

since hours i am trying to get the **name of the city** by using the **latitude and longitude** values wich i will get from a input box to my x,y variables but no example worked :(

I also read in the google maps api but it was not usefull.

I already have an api key.




Do you maybe have any solution ??

This example i got from the website and tried but without success:

    function myFunction() { var x='xxxxx'; var y='xxxxx'; //my coordinates 
        var geocoder = new google.maps.Geocoder;




        var latlng = {lat: parseFloat(x), lng: parseFloat(y)};
        geocoder.geocode({'location': latlng}, function(results, status) {
            if (status === google.maps.GeocoderStatus.OK) {
            // ...
            } else {
                window.alert('No results found');
            }
            } else {
                window.alert('Geocoder failed due to: ' + status);
            }
        });
    }




 </script>



hope you will help me.

best regards