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 9197097
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T21:59:53+00:00 2026-06-17T21:59:53+00:00

I am trying out the geocoder gem and looking to acceess the viewport results.

  • 0

I am trying out the geocoder gem and looking to acceess the viewport results.

Being new to Ruby is there a better way to access the result.

result = Geocoder.search("New York, NY").map(&:geometry)
north_east_lat = result[0]["viewport"]["northeast"]["lat"]
north_east_lng = result[0]["viewport"]["northeast"]["lng"]

While this does work it looks ugly and brittle

Any advise on making this better?

  • 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-17T21:59:54+00:00Added an answer on June 17, 2026 at 9:59 pm

    As far as I see, geometry data is just a simple Hash. If you don’t like the way you have to access values by [“key”] at multiple levels, you can convert Hash to OpenStruct.

    require 'ostruct'
    
    result = Geocoder.search("New York, NY").first
    # singleton class http://www.devalot.com/articles/2008/09/ruby-singleton
    class << result
      def ostructic_geometry
        ostructly_deep self.geometry
      end
    
      private
        def ostructly_deep(hash)
          root = OpenStruct.new
    
          # http://www.ruby-doc.org/stdlib-1.9.3/libdoc/ostruct/rdoc/OpenStruct.html#method-i-marshal_load
          # -- from the user comment at the bottom --
          # In the marchal_load() example, the Hash should have symbols as keys:
          # hash = { :time => Time.now, :title => 'Birthday Party' }
          load_data = hash.each_pair.inject({}) do |all, (key, value)|
            value = ostructly_deep(value) if value.is_a?(Hash)
            all[key.to_sym] = value # keys need to be symbols to load
            all
          end
    
          root.marshal_load load_data
          root
        end
    end
    
    now_you_can_call_value_from_member_geometry = result.ostructic_geometry
    now_you_can_call_value_from_member_geometry.bounds.northeast.lat # => 40.9152414
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently trying out Aptana Studio 3 for PHP development (I'm pretty new to
Am trying out the JMS example bundled with Apache Camel ApplicationContext context = new
Is there any way to effectively/accurately pull out a neighborhood within a city based
I am using geocoder and the devise gem. And i am trying to get
I'm trying to figure out a nice way to limit the rate at which
Trying out PDO for the first time. $dbh = new PDO(mysql:host=$hostname;dbname=animals, $username, $password); $stmt
Am pulling my hair out trying getting GeoCoder working. I went so far as
Am trying out ImageResizer and am looking for a good method to dynamically Authorize
Just trying out this IDE but it already looks better than NetBeans in terms
Trying out the example usage of codebrew rails-backbone , everything works fine but the

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.