简体   繁体   English

将Google Maps远程服务的持续时间转换为Javascript中的分钟

[英]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作为字符串以以下格式返回:

  • 50 minutes 50分钟
  • 1 hour 40 minutes 1小时40分钟
  • 1 day 2 hours 20 minutes 1天2小时20分钟

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属性具有两个属性: textvalue 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM