V
V
Viktor Viktorov2019-10-25 17:42:32
Yandex maps
Viktor Viktorov, 2019-10-25 17:42:32

How to make a button on the site to build a route with a transition to Yandex maps?

The following code is currently being used:

<a href="https://yandex.ru/maps/?rtext=55.659173,37.762848&rtt=mt">Построить маршрут в Яндекс.Карты</a>

but the route is built from this point, but you need from the current location to it.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
C
Casper969, 2020-03-25
@Casper969

Everything is much simpler
. Just put a tilde in front of the coordinates)

<a href="https://yandex.ru/maps/?rtext=~55.659173,37.762848">Построить маршрут в Яндекс.Карты</a>

and remove unnecessary attributes

M
mahmudchon, 2019-10-25
@mahmudchon

Alternatively, if there is an API to use.
https://tech.yandex.ru/maps/jsbox/2.1/geolocated_m...
Paste this code and Update.

ymaps.ready(function () {
    var myMap = new ymaps.Map('map', {
        center: [55.753994, 37.622093],
        zoom: 9,
        // Добавим кнопку для построения маршрутов на карту.
        controls: ['routeButtonControl']
    });

    var control = myMap.controls.get('routeButtonControl');

    // Зададим координаты пункта отправления с помощью геолокации.
    control.routePanel.geolocate('from');
    
    control.routePanel.state.set({
        type: "pedestrian",
        to: '55.659172, 37.762848'
    });

    // Откроем панель для построения маршрутов.
    control.state.set('expanded', true);
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question