Grouping similar information on the map according to a specific criteria is called points of interest. This is a term used for markers or points on the maps that can be categorized or grouped together. We will use locations as the points of interest in our application. We will call all the locations in our system and search the friends according to it. We will use the geocoder API to do this.
We will create location-based filters for our users in this task:
The
geocoder
gem has a method callednear
, which takes the location string as the parameter and runs a spatial query on the database:1.9.3p327 :001 > user = User.first 1.9.3p327 :002 > user.friends.near("NY")
We got six results when we searched for the term
NY
:1.9.3p327 :003 > user.friends.near("NY").length Friend Load (1.6ms) SELECT friends.*, 3958.755864232 * 2 * ASIN(SQRT(POWER(SIN((40.7143528 - friends.latitude) * PI() / 180 / 2), 2) +...