1
votes

I'm using geocoder for finding the places near user location . but it gives only longitude / latitude (or nearby places if some places are stored before ). The thing i want to get is when a user puts area name say 'statue of liberty' then result should show places near 'statue of liberty' having a specific tag say 'Hotel'

There is a web having the great implementation of it . You can check it Here

I'm not asking for full codes snippets rather i'm looking for useful suggestions that how i can make my application work or i have to change my gem . any help will be appreciated

3

3 Answers

0
votes

To find a Place near "statue of liberty" that has the "hotel" Tag, it would look like this:

Place.near("statue of liberty").where(tags: [:hotel]).all

Since you've provided absolutely no information about your schema or models, I've used general names. This is how I have always done it though.

Please refer to the GeoCoder docs for additional information.

0
votes

Use Geonames_api.

Then You can develop function, and send to it zipcode, and radius (distance) as the following:

def nearby(zipcode, radius)
  GeoNamesAPI.username = "[email protected]"
  GeoNamesAPI.lang = :en
  geo_name_objects = GeoNamesAPI::NearbyPostalCode.where(country: "US", postalcode: zipcode, radius: radius)
  zip_codes_names = geo_name_objects.postal_codes.map{|h| h.slice("postalCode").values}.flatten.uniq - [zipcode]
end

This function will return all zipcodes near by the current zipcode with distance less/equal the exist radius

0
votes

I personally use geokit and geokit-rails gems. To use them, you simply need to add acts_as_mappable :default_units => :kms (or miles) to the model you want to be able to locate, and then simply use:

Example model: location.rb

Location.closest(origin: "statue of liberty")

as a normal activerecord query, which can be chained with whatever you want .where(tags: [:hotel]).

TIP: geokit uses external geocoders, default is google geocoder, which give timeout errors if called too often. I suggest using Redis to cache geocoding results in a key-value way, such as $redis[address] = location_id and have a method that retrieves a location right away if it is in a cache. That way you can greatly lower the risk of geolocation timeout errors.