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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T09:59:47+00:00 2026-05-12T09:59:47+00:00

Has anyone done this? I’m confused at how I can make this work, first

  • 0

Has anyone done this? I’m confused at how I can make this work, first off I have my user model

Geocoding with it works fine in IRB, just can’t figure out how to get it to work in my project.

Trying to use some examples from the readme here: http://github.com/andre/geokit-rails/tree/master.

Anyhow here is what I have:

class User < ActiveRecord::Base

  # geokit
  acts_as_mappable

  after_save :locate

  def locate
    location = Geokit::Geocoders::MultiGeocoder.geocode("12.12.12.12")
  end

end

This corresponds with my save action in my userController, I need to do this after save because authlogic provides the IP after it saves the user or session. I think eventually I’ll make it a background process, but till then how can I get this to work? I have a location column in the user model that I’ll store the results of geocode()

Also right now I just have some arbitrary IP address “12.12.12.12” but it should actually be current_login_ip

  • 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-12T09:59:47+00:00Added an answer on May 12, 2026 at 9:59 am

    For one of my current projects I accomplished something very similar to what you are trying to do. The big thing to consider is that you do not want to do a new geocoding request every time a model is saved. It is rather time consuming and inefficient to do if you do not need to get new geocoordinates every time.

    Also geocoding results obtained from IP addresses are highly inaccurate. Sometimes you will get decent results, but many time you will get coordinates of some data center in another nearby town. If you are looking for regional accuracy, IP geocoding accuracy may be good enough for what you’re trying to do.

    This is how I tackled the problem of not rerequesting geocoding if the attributes had not changed:

    require 'us_states' # this is just an array of states and abbreviations
    include Geokit::Geocoders
    
    class Location < ActiveRecord::Base
    
        acts_as_mappable
    
        validates_presence_of :name, :address_1, :city, :state, :zip
        validates_format_of :zip, :with => /^([0-9]{5})(-[0-9]{4})?$/
        validates_inclusion_of :state, :in => US_STATES_ABRS
    
        before_save :get_geo_coords
    
        # request_geocoding attribute is intended to help with unit testing
        attr_accessor_with_default :request_geocoding, true
    
        private
    
        def get_geo_coords
            # if lat and lng are already defined
            if self.lat && self.lng && self.id
                # find existing location
                l = Location.find(self.id)
                # and if location params are the same as existing location
                # then we do not need to request geocords again
                loc_attrs = %w{address_1 address_2 city state zip}
                if loc_attrs.all? {|attr| self.attribute_for_inspect(attr) == l.attribute_for_inspect(attr)}
                    self.request_geocoding = false
                end
            end
            if self.request_geocoding
                # Request new geocoding
                loc = MultiGeocoder.geocode("#{self.address_1}, #{self.city}, #{self.state}, #{self.zip}")
                if loc.success
                    self.lat = loc.lat
                    self.lng = loc.lng
                else
                    errors.add_to_base("Unable to geocode your location.  Are you sure your address information is correct?")
                end
            end
        end
    end
    

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 260k
  • Answers 260k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer anjlab's sql profiler sqlprofiler.googlepages.com does what I need. its quite… May 13, 2026 at 11:24 am
  • Editorial Team
    Editorial Team added an answer select * from your_table order by int_category_id, int_order May 13, 2026 at 11:24 am
  • Editorial Team
    Editorial Team added an answer I found solution, gility is default "Mouse Configuration". Lenovo USB… May 13, 2026 at 11:24 am

Related Questions

Has anyone done this? I'm confused at how I can make this work, first
Has anyone done this? I have found the AlphaVSS project on Codeplex, but is
Has anyone done this successfully? As I understand, GDI+ 1.1 only ships with Vista.
How can I achieve this? I am trying to load content from the database
This is probably a very silly question. I am trying to do a geolocation

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.