K
K
Kirill2020-05-11 02:16:07
API
Kirill, 2020-05-11 02:16:07

Looking for the nearest object on the map?

I have a collection of my points (elements) on a map. There are 20 of them now. I need to determine the user's location by clicking and search for the nearest point that is on the map.

GeoQueryResult(objectCollection.toArray()).getClosestTo(result.geoObjects.get(0).geometry._coordinates).balloon.open();

objectCollection- a collection of points on the map - user coordinates (everything works well here) If you try the example from Yandex , then everything is fine, BUT if I replace the cafe variable from the example with my collection, then nothing works. Maybe I need to convert my collection to something else? Collection does not work.
result.geoObjects.get(0).geometry._coordinates

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Kirill, 2020-05-11
@kustiktm_kirill

Issue resolved.

ymaps.geoQuery(myMap.geoObjects).getClosestTo(result.geoObjects.get(0).geometry._coordinates).balloon.open();

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question