[英]Convert duration of google maps distance service to minutes in Javascript
I am using google maps distance matrix service that returns the duration
as string in the format like: 我正在使用Google Maps距离矩阵服务,该服务将
duration
作为字符串以以下格式返回:
For further processing I want all these string values to be converted in minutes. 为了进一步处理,我希望所有这些字符串值都可以在几分钟内转换。 Looked for existing conversion plugins but didn't find any.
寻找现有的转换插件,但未找到任何插件。 Is there an easy way to do this conversion?
有没有简单的方法可以进行此转换?
As per the documentation , the duration
property has two attributes : text
and value
. 根据文档 ,
duration
属性具有两个属性: text
和value
。 The value
attribute returns the time in seconds. value
属性返回以秒为单位的时间。 You can easily get the minutes from that value. 您可以轻松地从该值获取分钟。
Sample response: 样本回复:
{
"status": "OK",
"duration": {
"value": 340110,
"text": "3 jours 22 heures"
}
You can do something like: 您可以执行以下操作:
console.log((duration.value)/60); //Returns duration in minutes.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.