C
C
Castiel2016-04-15 09:56:24
JavaScript
Castiel, 2016-04-15 09:56:24

How to determine which city is in a leafletjs map?

There is a map shown using leafletjs, how to do the same as on Yandex.taxi, when moving around the map, when different cities are shown in the display area, the list of taxi services changes?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
E
Edward, 2016-04-16
@ED98

The procedure is as follows:

  1. Get the coordinates of the current map center: getCenter()
  2. Convert these coordinates to a city name using reverse geocoding. Such an opportunity is provided, for example, by Nominatim
  3. Depending on the city, update the list of taxi services

A
Alexey Ukolov, 2016-04-15
@alexey-m-ukolov

Leaflet knows nothing about cities. But he knows about the coordinates. Obviously, you need to store the coordinates of cities and, when moving the map, look for those that fall into the current viewport.

A
Andrey Belokopytov, 2016-04-15
@belokopytoff

To search for a city by coordinates, you can use the free Yandex Geocoder API https://tech.yandex.ru/maps/doc/geocoder/desc/conc...

M
Michael, 2016-04-15
@id194695811

I can offer kostylidze :) OpenWeatherMap also provides the name of the city along with the weather

navigator.geolocation.getCurrentPosition(function(position){

  $http.get('http://api.openweathermap.org/data/2.5/weather?lat=' + position.coords.latitude + '&lon=' + position.coords.longitude + '&appid=API_KEY')
    .success(function(location) {
      $scope.city = location.name;
  })

})

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question