S
S
sashavol2016-11-26 13:16:45
JavaScript
sashavol, 2016-11-26 13:16:45

Find the nearest point by clicking on the yandex map?

Good afternoon geniuses, js, and especially yandex map api!

Faced a problem that with my knowledge of js can not be solved.

My task is the following, I have about 10 points (balloons) on the Yandex map and I need to find the closest one to me when I click on the button, the task is complicated by the fact that from the beginning I have to get my location:

navigator.geolocation.getCurrentPosition(showPosition);
    function showPosition(position) {
        var y = $('#avMyPosition').val(position.coords.latitude + ', ' + position.coords.longitude);
    }

And I immediately write it to the hidden input

. This is all good, but I get it after loading the map, and in order to get it again, I need to reload the map, and it is advisable to do this by clicking the button so that the balloon opens after that. Actually in it and a problem it is impossible to make it.

Here is an example in jsfiddle https://jsfiddle.net/7gzryeu9/

And I will say, if you have coordinates ready in advance, then it correctly shows everything, shows the nearest open balloon.

Thanks for any help :)

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