S
S
SergeyFeschukov2015-08-26 12:36:12
API
SergeyFeschukov, 2015-08-26 12:36:12

Yandex.Maps API - YMapsML and the entry of the address into the polygon?

I connect Yandex.Maps, insert the created objects using YMapsML, then try to determine if the address is included in the created polygon. But on any address issues that the address is not included in the zone.

/* Инициализация Яндекс.Карты и подключение YMapsML */
var ymap, mymap, polygon;
function YMinit (lat, long) {
  ymap = new YMaps.Map($('#YMaps'));
  ymap.setCenter(new YMaps.GeoPoint(76.56738030, 60.94011121), 2);
  mymap = new YMaps.YMapsML('https://maps.yandex.ru/export/usermaps/***********/');
  ymap.addOverlay(mymap);
  YMaps.Events.observe(mymap, mymap.Events.Load, function() {
      var obj = this.filter(function (obj) {
        return obj.name == 'В черте города';
      });
      polygon = obj[0];
    });
}
YMaps.load(YMinit);

/* Попытка определения адреса */
var addr = 'Мира, 23';
var geocoder = new YMaps.Geocoder(addr + ', Нижневартовск');
YMaps.Events.observe(geocoder, geocoder.Events.Load, function(geocoder) {
  if ( geocoder.length() ) {
    var point = geocoder.get(0).getGeoPoint();
    if ( !polygon.contains(point) ) {
      console.log('К сожалению, адрес не входит в зону доставки!');
      return false;
    } else
      console.log('Всё в порядке');
  } else {
    console.log('К сожалению, адрес не входит в зону доставки!');
    return false;
  }
});

If we take the coordinates from the YMapsML file and create a polygon inside the script (similar to the article from gyktimes ), then the address determination is successful.
What am I doing wrong? I compared polygon objects obtained by different methods, they seem to be no different.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question