user3079933
user3079933

Reputation: 63

GEOCODER: Fetching User Geolocation to generate status updates with location attributes in rails 3

I am totally new to RoR (currently using Ruby 1.9.3 and Rails 3.2.16). I have read lots of tutorials and ebooks on how to use rails in the last few days.

Now I want to create some kind of blog for multiple users ( a traveling journal for me and my friends), that automatically fetches the user location (IP address). This should be used for writing a status update that inherits the user location automatically. But it should update the user location within a certain time period to make sure when the user is moving the next status update will get a different location. e.g. User1: "I am at the supermarket" - 4th Ave, NY ....10mins later User1: "Now I am standing at the bus stop down the block" - 5th Ave, NY

Other feature should be a .find or .where method to show all statuses that were made at a specific location nearby the actual user location.

I know how to make a simple blog with devise and adding status model to it, but I have no idea how to implement the geocoding feature into that. Planed to use https://github.com/alexreisner/geocoder for the whole geocoding process.

I hope some of your RoR pros can help me with this problem or at least give me a hint how to implement it :))

EDIT: I guess I've found a tutorial that fits my needs. There is just two things. I dont wan't maps to be included and i want to store the geodata (location, lat and lng) in a database. Can anyone of you tell me which part of the code i can delete and how i can parse the json to the "location" database? http://de.slideshare.net/nebirhos/geolocation-on-rails

Upvotes: 0

Views: 1080

Answers (1)

nil
nil

Reputation: 2278

You should probably look into client side geocoding vs server-side. You're going to need to do a reverse-geocode; which is to grab your user's location with latitude and longitude and convert that into an address.

So basically you can worry about that after you've got your application built.

If you go the geocoder route you include latitude and longitude fields and an ip address. Users can also be reversed geocoded by ip.

So for simplicity say that you currently have a Post model. That post would typically have a

    ipaddress:string title:string post:string latitude:string longitude:string

Ruby Geocoder has worked great for me, but I plan on my next refactor to go client side.

Here is Google's recommended strategies for Geocoding. This might be pretty helpful

https://developers.google.com/maps/articles/geocodestrat

EDIT User need more info

Here is Ruby Geocoder's example of ip request on a User Model:

app/models/user.rb

    geocoded_by :ip_address,
   :latitude => :lat, :longitude => :lon
   after_validation :geocode

Checkout the main site for a lot of useful info: http://www.rubygeocoder.com/

And also have a look at the railscasts Geocoder Video. Since your using an older version of ruby and rails, these resources should be especially helpful. The 9 bucks will be worth it.

http://railscasts.com/episodes/273-geocoder

Upvotes: 1

Related Questions