S
S
Sergey questions2018-06-01 00:48:20
JavaScript
Sergey questions, 2018-06-01 00:48:20

How to get city name based on OpenLayers 3/4 geo coordinates?

Hello.
I am creating a map in OpenLayers and have a few questions.
https://jsfiddle.net/9x10yet0/
The main issue now is getting the name of the city based on the geo coordinates of latitude and longitude, I just can’t understand the solution, the search does not give anything good.
In Google, everything is done very simply and tritely:

var GEOCODING = 'https://maps.googleapis.com/maps/api/geocode/json?latlng=' + тут коодинаты широты + '%2C' + тут коодинаты долготы + '&key=ключ api гугла';
  $.getJSON(GEOCODING).done(function(location) {
    // Название города
    var city = location.results[0].address_components[2].long_name;
  };

How can I do this in openlayers?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Moskus, 2018-06-01
@smartycms

Google Maps API and Geocoding API are combined in one product. And OpenLayers is a framework only for displaying maps and interacting with their sources (TMS, WMS, etc.). It is not an integrated part of OpenStreetMap. You need to use the separate Nominatim API, e.g. https://wiki.openstreetmap.org/wiki/Nominatim

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question