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
  • 1 View
  • 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

Related Questions

Has anyone done this / have some example code?
Has anyone done this? I have found the AlphaVSS project on Codeplex, but is
Has anyone done this or attempted to do this for a preexisting project? It
Has anyone done this successfully? As I understand, GDI+ 1.1 only ships with Vista.
Has anyone done this? I would like to show a ! instead of a
Has anyone done this? Is it an easy process? We're thinking of switching over
I wanted to see if anyone has done this. In ruby, i'd like to
I am starting migration process from python to jython. Has anyone done this with
Has anyone done this? What apis/approaches were used?
Has anyone done this before. I am having trouble understanding the example play provided.

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.