Answer the question
In order to leave comments, you need to log in
How to depict a region or city polygon on yandex maps?
Colleagues, good day, I ask for help from Yandex map experts.
I am doing one service and there is a map on which you can search for a list of company objects and the actual search by region and city, and there is one point that I can’t decide, so:
ymaps.geocode('владивосток', {
results: 1
}).then(function (res) {
var firstGeoObject = res.geoObjects.get(0),
coords = firstGeoObject.geometry.getCoordinates();
console.log(coords);
});
Answer the question
In order to leave comments, you need to log in
The essence of the task: on the page (no matter what service) there are maps and there is an input to search for regions or settlements, and so on, let's call it target. I need to find the coordinates of the target, and draw the borders of the target on the map, one way or another, I solved the task, through the Yandex maps api:
ymaps.ready(init);
function init() {
var myMap = new ymaps.Map('map', {
center: [55.753994, 37.622093],
zoom: 9
});
ymaps.geocode('владивосток', {
results: 1
}).then((res) => {
let firstGeoObject = res.geoObjects.get(0);
let coords = firstGeoObject.geometry.getCoordinates();
console.log(coords);
ymaps.borders.load('RU').then((geojson) => {
console.log(geojson);
}, (e) => {
console.log(e);
});
});
}
In the documentation
How it works
At the request "Moscow, st. Leo Tolstoy, 16" geocoder will give the coordinates of this house - [37.587874, 55.73367] . And if you specify the geographic coordinates of the desired point in the request - say, [27.525773, 53.89079], then the geocoder will return the address: Minsk, Prospekt Dzerzhinsky, 5.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question