How do you limit the search area in the Yandex Card?



  • How do you limit the search area to the Potatoes? I mean, looking for a separate rectangle, attached coordinates, or a across town? I tried to do that, zero effect.

    myMap.setBounds([
                      /* Координаты юго-западного угла области просмотра
                         карты */
                      [56.366411 , 60.032195],
                      /* Координаты северо-восточного угла области
                           просмотра карты */
                      [56.584157, 60.463256]
                      ], {
                          // Включить проверку доступного
                          // диапазона масштабов (исключает
                          // возможность попасть в "серые тайлы")
                          checkZoomRange: true,
                          // Можно анимировать перемещение карты
                          duration: 500
                      }
                    );
    var myGeocoder = ymaps.geocode(
                          /* Строка с адресом, который нужно
                             геокодировать */
                          "Екатеринбург", {
                            /* Опции поиска:
                                - область поиска */
                            boundedBy: myMap.getBounds(),
                            // - искать только в этой области
                            strictBounds: true,
                            // - требуемое количество результатов
                            results: 1
                        });
    
                /* После того, как поиск вернул результат, вызывается
                   callback-функция */
                myGeocoder.then(function (res) {
                  /* Размещение полученной коллекции 
                     геообъектов на карте */
                  myMap.geoObjects.add(res.geoObjects);
                });
    



  • Everything works as described in the documentation. Maybe you don't have an object in a given rectangle. In this case, nothing will be found or marked on the map.

    I tried to find an object that's obviously on the map and it's found.

    For example, finding Lenin's street in some towns (beginning to look for Lenin's area, but Chelabinsk was so severe that there was no such area).

    ymaps.ready(function() {
      var myMap, cityList, lookAtLenin;
      myMap = new ymaps.Map('map', {
        center: [56.70, 60.20],
        zoom: 10
      });
      cityList = new ymaps.control.ListBox({
        data: {
          content: 'Выбрать город'
        },
        items: [
          new ymaps.control.ListBoxItem({
            data: {
              content: 'Екатеринбург'
            },
            options: {
              selectOnClick: false
            }
          }),
          new ymaps.control.ListBoxItem({
            data: {
              content: 'Москва'
            },
            options: {
              selectOnClick: false
            }
          }),
          new ymaps.control.ListBoxItem({
            data: {
              content: 'Челябинск'
            },
            options: {
              selectOnClick: false
            }
          }),
        ]
      });
      cityList.get(0).events.add('click', function() {
        lookAtLenin('Екатеринбург');
      });
      cityList.get(1).events.add('click', function() {
        lookAtLenin('Москва');
      });
      cityList.get(2).events.add('click', function() {
        lookAtLenin('Челябинск');
      });
      myMap.controls.add(cityList, {
        floatIndex: 0
      });
      lookAtLenin = function(city) {
        var cityCenter = {
          'Екатеринбург': [56.79, 60.61],
          'Москва': [55.66, 37.64],
          'Челябинск': [55.15, 61.50]
        };
        myMap.setCenter(cityCenter[city], 9, {
          checkZoomRange: true,
          duration: 500
        }).then(function(res) {
          return ymaps.geocode('ул. Ленина', {
            boundedBy: myMap.getBounds(),
            strictBounds: true,
            results: 1
          });
        }).then(function(res) {
          myMap.geoObjects.add(res.geoObjects);
        });
      };
    });
    <script src="https://api-maps.yandex.ru/2.1/?lang=ru"></script>
    <div id="map" style="width: 100%; height: 250px;"></div>




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2