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

  • SEARCH
  • Home
  • 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 6359321
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T23:30:10+00:00 2026-05-24T23:30:10+00:00

So i am trying to re-organise some data from the Google Places API, currently

  • 0

So i am trying to re-organise some data from the Google Places API, currently it comes out of their API like this:

{"results"=> [
             {"geometry"=>{"location"=>{"lat"=>51.503815, "lng"=>-0.11007}}, "icon"=>"http://maps.gstatic.com/mapfiles/place_api/icons/restaurant-71.png", "id"=>"5f212d158f4181db3ac0619fb3c52f36d4e276c2", "name"=>"Madeira Cafe", "reference"=>"CnRjAAAApaZWmTl5wOMtW49q3D1BLKAJ_M8lmZxaD6_-AU92qWfVZdokfTWOzlp5En_r9hSUHx-EeP71hzH7iDPYAGPtiqEAXvT4WcI3xlc5XUivenbQLw0j5MHW-ErL-Hbk4xB_by0OSsXCz9etNgkjbp0QCRIQ82Dgj-I3DAJqr7I3EwsFEhoUm2RXf2rCFlSuhfKjSsPuWKA2VGA",     {"results"=> [{"geometry"=>{"location"=>{"lat"=>51.503815, "lng"=>-0.11007}},
              "icon"=>"http://maps.gstatic.com/mapfiles/place_api/icons/restaurant-71.png",
              "id"=>"11111111",
              "name"=>"Madeira Cafe",
              "reference"=>"xxxxx",
              "types"=>["restaurant", "food", "establishment"],
              "vicinity"=>"London"}]}

The results get put into a hash with one key value – "results"

The rest of the data is the nested inside (i think) with "geometry" being the first of each record.

What I am trying to get to is a neat Hash that has one ID per place, with Lat / Lng and Name stored… so it can be stored and queried.

I have tried something like this:

results_hash = {}
result.each do |geometry, location, id|
  results_hash[id] = geometry
end

p results_hash  

but I can’t get it to work… it always outputs nil or just the same hash?

I hope this makes sense, as usual if someone just says “read this” its still a great help.

Thanks!

Charlie

  • 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-05-24T23:30:11+00:00Added an answer on May 24, 2026 at 11:30 pm

    Sounds like you want this:

    results_hash = result["results"].inject({}) { |h, res| h[res["id"]] = res["geometry"]; h }
    

    This gives you the following hash (printed with awesome_print):

    {
        "2d48a3306535b60663645323cdf972c320da8b9d" => {
            "location" => {
                "lng" => -0.114522,
                "lat" => 51.502653
            }
        },
        "5f212d158f4181db3ac0619fb3c52f36d4e276c2" => {
            "location" => {
                "lng" => -0.11007,
                "lat" => 51.503815
            }
        }
    }
    

    You’d probably want to format it slightly nicer:

    results_hash = result["results"].inject({}) do |h, res| 
      h[res["id"]] = res["geometry"]
      h
    end
    

    Or if you are using 1.9:

    results_hash = result["results"].each_with_object({}) do |res, h| 
      h[res["id"]] = res["geometry"]
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to jump through some hoops to organize data in a special way.
Trying to get my css / C# functions to look like this: body {
I'm getting a bit of a headache trying to figure out how to organise
I'm trying to write a quick (ha!) program to organise some of my financial
I am trying my first flex application. And have a problems adding data from
I am planning to create a screen saver. Thinking of trying out some WPF
I would like for two of my python files to import some methods from
I'm trying to figure out what to do here. I have customer data in
I am trying to add some shortcut handlers like Ctrl+B in my Silverlight application.
I am trying to write some google map functionlity and playing around with javascript

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.