Search code examples
mysqlruby-on-railsrubysearchgeo

How to search nearby data with geocoder and other search tool?


I am using geocoder ruby gem in a Rails project. Now want to get nearby location search result. The search gem is using nazrin which operate CloudSearch on AWS. So the following way is what I tried:

City.near([39.905, 116.39139], 10).search.size(20).start(1).query('Hotel').execute

It doesn't work. It returned all the results but not nearby the location([39.905, 116.39139]) which pointed.

It seems that near([39.905, 116.39139], 10) didn't fit the search method after it. But if use Spot.near([39.905, 116.39139], 10) itself, can get data nearby [39.905, 116.39139].

So, how to use them together?


Solution

  • You can use Google Map API

    https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=-33.8670,151.1957&radius=500&types=food&key=API_KEY

    To find the nearby location by location types. for example in the above api types=food. This will gives the all the nearby hotels, food stores etc within 500 meter radius.