Geocoder is a Ruby Gem, used for geocoding. It can find geographical coordinates as listed above including user location. Also it can find address from coordinates and nearby places to specific address. By keeping address, latitude and longitude of tagged locations in a model, Geocoder can fetch nearby places to a specific address at a given distance (in miles).
For more information about implementation, https://github.com/alexreisner/geocoder can help you.
- Geocoder.address(“latitude,longitude”) -> gets geographic street address of the given latitude and longitude values.
- Geocoder.coordinates(“IP address”) -> gets geographic coordinates of IP address specified, as an array with index 0 and 1.
- request.ip = gets user IP address
- Geocoder.coordinates(request.ip.to_s) -> gets geographic coordinates of user IP location, as an array with index 0 and 1.
- Geocoder.coordinates(“address”) -> gets geographic coordinates of a specific city address, as an array with index 0 and 1.
- Geocoder.address(request.ip.to_s) -> gets geographic street address of user IP location
- To implement geotagging using Geocoder, follow the steps
class Tag < ActiveRecord::Base
after_validation :geocode, :if => :address_changed?
Tag.create(:file_id => file_id, :address => address, :latitude => params[:lat] , :longitude => params[:lng])
- If our computer has GPS built-in (such as on many mobile devices and some laptops), it will know exactly where we are.
- For devices without GPS, it can often provide a very good approximation based on nearby known wireless signals and other factors, such as tracing what routers our computer goes through when connecting to the internet.
- This makes it much more useful for webapps that have a navigation or location component.
- Most of the recent versions of browsers have support for HTML5 geolocation, like Opera, Firefox, Chrome, Safari etc.
- IP-based GeoLocation depends on databases associated with ISP’s to find out where a user is.
- This will get failed, when our ISP services a very large area and gives out dynamic IP addresses.
- The address for one town today might be 100 miles away tomorrow. These databases are usually not updated frequently.
- If our ISP sells off blocks of IPs or moves them to a new town, the database may still incorrectly think like we are somewhere else.
- HTML5 geolocation uses services provided by our browser to figure out where we are.
- If location data needed in app, using HTML5 GeoLocation may be better than IP based.
- We have to click ‘share’ in browser to allow our location to be shared.
- By setting up a fallback, we can use a IP based Geolocation if HTML5 Geolocation fails.