Answer the question
In order to leave comments, you need to log in
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;
}
});
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question