R
R
Roman Andreevich2019-03-12 08:37:10
JavaScript
Roman Andreevich, 2019-03-12 08:37:10

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);
            
        });

using geocode I get the coordinate of the center of the region or city (to move around the map itself) all the rules, but the question arose of highlighting the found region or city. Actually the question is how to get a list of coordinates of a region or city?
in the developer tool, I spied on such a thing as displayGeometry, on an object that produces a pool of coordinates. But I can't find in the documentation how to get the coordinates.
Thanks in advance for any advice.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Roman Andreevich, 2019-03-12
@RomanDillerNsk

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);
               
            });
            
        });
}

According to the terms of Yandex, you can cache data for several days, so this solution can probably be used on your cards and so on !!! :))))
The task is of course specific, but nevertheless it may be useful to someone)
Thank you very much!

C
Chris, 2019-03-12
@tv_dakota


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 question

Ask a Question

731 491 924 answers to any question