I have latitude and longitude of an address and I want to search all the airports, Railway stations, Bus Stand and cafe etc popular places. I'm using these gems in my application :
gem 'geocoder'
gem 'gmaps4rails'
gem 'geokit-rails
Now Please suggest me how can I solve this problem?
We can pass the search parameters in type (these search strings are suggested by google for places)
lat="30.987674"
lng="-45.098753"
doc = JSON.parse(open("https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=#{lat},#{lng}&radius=50&type=['cafe']&name=cruise&key=xxxxxx").read)
cords=[]
doc['results'].each do |r|
tmp={}
tmp = r['geometry']['location']
tmp["name"] = r['name']
cords<< r['geometry']['location']
end
Here cords is the array of hashes with relative information about places i.e. cafes.
See : https://developers.google.com/places/web-service/search
https://developers.google.com/places/supported_types
I would actually use the near function of geocoder, assuming you use ActiveRecord.
Related
I'm using Geocoder with google places API on my Ruby on Rails api,
I would like to search locations but only if the city params match my query string.
Eg. Searching for 'X' locations return cities called 'X', with no chance of returning a street or country also called 'X'.
Geocoder.search.city('X') #I'm aware that this doesn't work
I have Place model with lat and long fields.
So i need to select all places and order them using my geoposition.
I think that i need to use Geocoder gem.
So user send to me his lat & long
and i need to do smth like
Place.where(status: 1).and order them using my lat long.
How can i do?
Thanks
You would use the near method:
Place.where(status: 1).near( "Party City, Utah", 20 ) # Finds places within 20 miles
This will grab all Place records that are within a specific radius of the given location. In this case, your location is "Party City, Utah". You can add additional arguments to the near method to limit the number of results, and also edit the radius of your query.
More information in the GeoCoder Docs
I'd like to check if the country name provided belongs to Europe.
Does anyone know of a list of european countries that can be used in a Ruby project?
I'd like to do something like this:
spain = Country.named('Spain')
spain.parent # => 'Europe'
japan = Country.named('Japan')
japan.parent # => 'Asia'
https://github.com/jim/carmen/ lets me list subregions of a country, but not a country's parent.
Try that gem if you really need whole gem for this. You should be able to do:
Country.find_all_countries_by_region('Europe')
to get countries in Europe.
Check out the Wikipedia article for a complete list. http://en.wikipedia.org/wiki/List_of_European_countries
I'm looking for a way to display my facets in a grouped list. For example i have some users and a facet to filter by country, this gives me:
Country
Holland (5)
England (2)
Egypt (5)
Rwanda (2)
And what i would like to have is:
Europe
Holland (5)
England (2)
Africa
Egypt (5)
Rwanda (2)
I'm using the Tire gem in a Rails application, my models and relations are like this: http://api.rubyonrails.org/classes/ActionView/Helpers/FormOptionsHelper.html#method-i-option_groups_from_collection_for_select
I've googled for an example on this for hours, just can't find anything for nested /grouped facets what makes sense to me in Elasticsearch. Hope someone can help me in the right direction! Many thanks in advance!
Daniel
You can probably handle this by indexing the data in two ways and then just parse the outout. Use the "object" version to apply filters, and get your parsing version as a facet to display filters.
For example:
"mydocument":{
"attributes":[
"location":{
{"continent":"europe",
"country":"england"
},
"fur_style":"long"
],
"facets":[
{"location":"Europe##england"},
{"fur_style":"long"
]
}
when you get your data back, you'll have:
"facets":[
{"location":"Europe##england",
"total":5},
{"location":"africa##egypt",
"total":7}
{"fur_style":"long",
"total":3}
etc etc
]
In your application, you just have to loop through and break apart the terms using the ## delimiter (or whatever you want it to be).
I have the following SOLR search where I am trying to find a few places in my database based on lat/lng using Geohashes and making sure that the places have an affiliate link through an Affiliates table.
search = Sunspot.search(opts[:types]) do
any_of do
0.upto(opts[:range]) do
geohash = GeoHash.encode(place.lat, place.lng, precision)
neighbors = GeoHash.neighbors(geohash) rescue []
geohashes = [geohash] + neighbors
with(:affiliate_names, ['company_a', 'company_b'])
with(:"geohash_#{precision}", geohashes)
precision -= 1
end
end
without(:class, IgnoreClass) unless opts[:types].include?(VacationRental)
end
search.hits
The issue I am running into is that this search pulls in both places within the geohash and places with the affiliate_names 'company_a' and 'company_b'. Specifically, these two lines:
with(:affiliate_names, ['company_a', 'company_b'])
with(:"geohash_#{precision}", geohashes)
I want the places to be filtered by geohash AND affiliate_name. Right now, the two with statements act like an OR.
How do I do a Solr Sunspot search to pull in records that fulfill both the with criteria?
I figured it out.
You can nest the code as follows
all_of
with(:affiliate_names, ['company_a', 'company_b'])
with(:"geohash_#{precision}", geohashes)
end
This will ensure that the solr record that you query fits both the requirement.