Answer the question
In order to leave comments, you need to log in
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>
Answer the question
In order to leave comments, you need to log in
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 questionAsk a Question
731 491 924 answers to any question