Is it possible from the data of the coordinates of width and longitude to receive the name of the city?

Welcome!

There is a field to enter the address, which is linked to the Google maps API. The template displays the address as text and the map widget. There is the possibility of transformation values, and the address field in the latitude and longitude. Need the ability to separately display only the city, not to make a separate taxonomy.
July 9th 19 at 12:53
2 answers
July 9th 19 at 12:55
Solution
This is called geocoding.
About it I know just can't figure out how to create such a function for use in Wordpress. Probably incorrectly formulated a question. - Jean.Fay71 commented on July 9th 19 at 12:58
: thank you I'll try - Jean.Fay71 commented on July 9th 19 at 13:01
Do an AJAX request for example, https://goo.gl/83q6BP (link cut, had to cut). - Domenick.Ste commented on July 9th 19 at 13:04
: if I understand correctly then put in the end of request &components=locality and get the city - Jean.Fay71 commented on July 9th 19 at 13:07
Not quite understand, that still need from the city coordinates or Vice versa. Here is the definition for coordinates https://goo.gl/ZD9Y8l Get JSON response in address_components has the object types locality, political. - Domenick.Ste commented on July 9th 19 at 13:10
: There is a full address, for example, Chernyshevskogo str., 44, Vologda, Vologda oblast, Russia right opportunity in the right place to put only the city in the example of Vologda. - Jean.Fay71 commented on July 9th 19 at 13:13
: The same object with the same type. The answer is the same for both queries. - Domenick.Ste commented on July 9th 19 at 13:16
: Thank you, the principle is clear I will understand. - Jean.Fay71 commented on July 9th 19 at 13:19
July 9th 19 at 12:57
Maybe someone useful will post here working code.

$geo = ""; // specify the source address, for example, the value of the field shortcode
$gmap_api = "http://maps.googleapis.com/maps/api/geocode/json?sensor=false&language=ru&address=".urlencode($geo); // refer to API
$request = file_get_contents($gmap_api); // process the result
$jsondata = json_decode($request, true); // decode json data
foreach ($jsondata["results"] as $result) { // get what we need
foreach ($result["address_components"] as $address) {
 if (in_array("locality", $address["types"])) {
 $city = $address["long_name"];
}
}
}
return $city; // ready

Find more questions by tags APIGoogle MapsPHP