我使用 Yandex API 计算从 A 点到 B 点的行程距离和价格。在我的示例中,您可以通过在地图的不同部分单击 2 次来尝试自己:http: //jsfiddle.net/EveGeen/wor9afo0/
ymaps.route([start, finish]).then(function (router) {
var distance = Math.round(router.getLength() / 1000),
message = '<span>Distance: ' + distance + 'km.</span><br/>' +
'<span style="font-weight: bold; font-style: italic">Price: %sр.</span>';
self._route = router.getPaths();
self._route.options.set({ strokeWidth: 5, strokeColor: '0000ffff', opacity: 0.5 });
self._map.geoObjects.add(self._route);
self._start.properties.set('balloonContentBody', startBalloon + message.replace('%s', self.calculate(distance)));
self._finish.properties.set('balloonContentBody', finishBalloon + message.replace('%s', self.calculate(distance)));
});
你会看到在A、B设置好之后,你可以按这些字母中的任何一个,它会显示距离和价格。
如何将这两个值(距离和价格,第 127-128 行)传递到顶部的两个输入中?我只需要没有文字的数字。