Geocoder (Ruby)

Uses your system voice; voice and rate in settings.

Snapshot

≈ 2 min read

Names in other languages

No names in other languages are held for this entry yet.

Article bodies are English and are not machine-translated. A name in another language is not a translation of the article.

Geocoder is a geocoding library for Ruby. Geocoding helps to enhance webpages by presenting location relevant information to the user. When used with Rails, Geocoder adds geocoding functionality such as finding coordinates with street addresses or vice versa in addition to distance calculations for ActiveRecord objects. Since the functionality does not rely on proprietary database functions, finding different geocoded objects in an area works out-of-the-box for databases like MySQL, PostgreSQL and SQLite.

Geocoder is a geocoding library for Ruby. Geocoding helps to enhance webpages by presenting location relevant information to the user. When used with Rails, Geocoder adds geocoding functionality such as finding coordinates with street addresses or vice versa in addition to distance calculations for ActiveRecord objects.

How it works

Since the functionality does not rely on proprietary database functions, finding different geocoded objects in an area works out-of-the-box for databases like MySQL, PostgreSQL and SQLite. rails plugin install git://github.com/alexreisner/geocoder.git geocoded_by :full_street_address # can also be an IP address after_validation :geocode # auto-fetch coordinates For reverse geocoding, Geocoder must know which method returns latitude and longitude coordinates.

If :address option is not provided, it fetches the address automatically in the address attribute.

Else, it fetches the address into the location attribute like the example given below. reverse_geocoded_by :latitude, :longitude, :address => :location after_validation: reverse_geocode # auto-fetch address Forward and Reverse Geocoding on the same model is possible. geocoded_by :address reverse_geocoded_by :latitude, :longitude after_validation :geocode, :reverse_geocode In order to use different names for latitude and longitude in the model, the following change may be done when implementing geocoded_by: geocoded_by :address, :latitude => :lat, :longitude => :lon Additionally, the address method may return any string that would be used to search Google Maps.

Any of the following examples will work: "123 Sample St, New York, NY" "Eiffel Tower, Paris, FR" "Raleigh, NC, US" Hotel.near("Raleigh, North Carolina") Finds hotels near Raleigh. @restaurant.distance_to("Empire State Building") Finds the distance from @restaurant to the Empire State Building.

Text derived from https://en.wikipedia.org/w/index.php?oldid=1374053868 under CC BY-SA 4.0; modifications have been made.

Sources cited in this revision

6 named source(s) extracted from the cited revision. A source with no author is shown by its publication; nothing is invented.