A
A
Ashley_ko2022-02-06 15:04:07
Yandex maps
Ashley_ko, 2022-02-06 15:04:07

How to get an object with data about the constructed route?

Using Ymaps in a React Project

<YMaps
  query={{
    apikey: "ключ",
  }}
>
  <Map
    defaultState={{ center: mapGeopmetry, zoom: 13 }}
    width="100%"
    height="100%"
    modules={["geolocation", "geocode"]}
    controls={["routePanelControl"]}
  >
    <RoutePanel
      // onOptionsChange={(e)=>console.log('request: ',+ YMaps.Map.controls.get('routePanelControl').routePanel.getRouteAsync())}
      //onOptionsChange={(e)=>console.log('request: ',+ new ymaps.Map.controls.get('routePanelControl').routePanel.getRouteAsync())}
      onGeometryChange={(e) =>
        console.log("route panel", e.get("target").geometry.getCoordinates())
      }
      options={{
        float: "none",
        maxWidth: "630px",
        showHeader: "true",
        position: {
          bottom: "70px",
          left: "0",
          right: "0",
        },
      }}
    />
  </Map>
</YMaps>


Please tell me how to get data from point A to B.
Detailed data is needed - coordinates, address names

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Tkachev, 2022-02-08
@Real_Farmer

YMaps.Map.controls.get('routePanelControl').routePanel.getRouteAsync().then(function(route) {
let activeRoute = route.getActiveRoute();
let distance =activeRoute.properties.get("distance")
let distance_km = Math.round(distance.value / 1000)
})
Help

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question