admin管理员组

文章数量:1415644

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);
        }
    });
}

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);
        }
    });
}
Share Improve this question edited Nov 26, 2016 at 21:27 jrbedard 3,7245 gold badges35 silver badges35 bronze badges asked Nov 24, 2016 at 17:04 sinantosinanto 111 silver badge1 bronze badge 4
  • 1 Give this a try: stackoverflow./questions/6797569/… – Bassie Commented Nov 24, 2016 at 17:06
  • geocodezip./v3_GoogleEx_geocoding-reverse2postcodeD.html – geocodezip Commented Nov 24, 2016 at 17:11
  • Wow thats it thank you :) LOVE THIS SITE ! – sinanto Commented Nov 24, 2016 at 18:29
  • Possible duplicate of How can I get city name from a latitude and longitude point? – Maksim Simkin Commented Nov 24, 2016 at 19:38
Add a ment  | 

1 Answer 1

Reset to default 3

Look out for Geo location API

Sample Request

http://maps.googleapis./maps/api/geocode/json?latlng=40.714224,-73.961452&sensor=false

本文标签: google mapsHow to find city name with latitude and longitude in JavaScriptStack Overflow