Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8559277
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T16:00:16+00:00 2026-06-11T16:00:16+00:00

I couldn’t solve this basic error, and I haven’t changed anything in my code

  • 0

I couldn’t solve this basic error, and I haven’t changed anything in my code but fixing the indentation of if clauses

I make a request to Google Direction’s API and capture the total travelling duration by car between the points. I try to capture it by using the code below;

duration = hash['routes'][0]['legs'][0]['duration'].fetch('value')

However when I try to make a comparizon like below it gives me errors;

if duration < timeToArriveSecond #where timeToArriveSecond is a parameter started with value -1. Integer value

Would it be possible for developers here to enlighten me as I’m stuck.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T16:00:18+00:00Added an answer on June 11, 2026 at 4:00 pm

    hard to say without knowing how the hash looks like but since your ‘routes’ and ‘legs’ returns an array key ‘value’ of duration seems also to do so, try to change your line as follows:

    duration = hash['routes'][0]['legs'][0]['duration'].fetch('value')[0]
    

    or since fetch works like [“value”] here

    duration = hash['routes'][0]['legs'][0]['duration']['value'][0]
    

    for me ist seems that hash looks something like this (as far as i can tell how you access it:

    irb(main):065:0* hash 
                     => {"routes"=>[{"legs"=>[{"duration"=>{"value"=>[1, 2, 3]}}]}]}
    irb(main):066:0> hash["routes"][0]["legs"][0]["duration"].fetch("value")
                     => [1, 2, 3]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I couldn't find anything on this, but probably its just because I don't know
Couldn't find anything relevant in forums So ,Please help me with this code .I'm
Couldn't find anything about this on the internet, or stackoverflow?!? Basic Example: A great
I couldn't find anything similar to this anywhere. I have an array of pointers
couldn't find a similar topic but this may boil down to not knowing how
Couldn't find anything on this with a Google Search. Does anyone know how to
Couldn't find an answer to this question. It must be obvious, but still. I
I couldn't find this in the docs , but how am I meant to
(Couldn't think of any simpler way to write the title for this, but the
couldn't they make it simple, all you need is just uid and passwd, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.