-2

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 which 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 useful.

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);
        }
    });
}
jrbedard
  • 3,662
  • 5
  • 30
  • 34
sinanto
  • 11
  • 1
  • 1

1 Answers1