Finding nearby addreses by geo location in rails - ruby-on-rails

I have stored users - including their addresses - and need to find all users who live within a certain distance of a specific location.
I am using geocoder and have stored longitude and latitude in the Users table.
How do I find these user?

To do a query based on lat/lon, do this:
User.near([39.41, 90.23], 10)
That will find users within 10 miles of the lat/lon pair.
Here are the docs: https://github.com/alexreisner/geocoder

Related

How to get nearby places using the geonames API?

we are trying to get nearby locations using the geonames API, we have used /findNearbyPostalCodes and /findNearbyPlaceName and /findNearby for example but we are getting some locations like parks and hotels, instead we want to get cities and populated locations, is there any way to do this ? Thanks.

Rails geocoder find near locations within different radius

I want to find close locations for an user. Users table have their latitude and longitude.
Locations table have their latitude and longitude. Also locations have a radius attribute. I want to find locations for an user, that the user is inside those locations within specific radius. I can't do Location.near([user.latitude, user.longitude], radius), because all locations have different radius.
Also I cannot do Location.all.to_a.select {|l| u.distance_from([l. latitude, l. longitude]) < l.radius}, because it'd be inefficiently. It must be placed in the main page. Now I have about 1k locations and 1k users.
How can I do that? I use gem geocoder, but I can use something else.

How could I query Firebase geo locations without GeoFire in order to return results based on distance between two points?

Firebase just updated their sdk to 3.x and the current version of GeoFire 2.x doesn't work.
What I would like to know is the best way to store geo location values so that I can query firebase so that we only return location with in a defined radius around the user.
Example: user defines that they would like all items that are within 20 miles or less from them.
I wonder if I could store a single value from the latitude and longitude that would allow me to quickly query for this data? Or maybe that isn't the right approach ?
It is not possible using pure firebase without implementing some sort of geohash (it is what geofire does). You could use an externa index stored in elastic search or in redis for example

Are geolocation apps based on latitude and longitude data?

Are most web and smartphone applications that show you how far other users are from you essentially based on a user's latitude and longitude? That is, do these apps basically derive a user's latitude and longitude from their country and postal code and then use an algorithm to create a sorted list of all users who are near them, closest first? I believe the answer is "yes" but I want to make sure before I build this feature into my Django application.
For those countries that don't use postal codes, I would imagine the latitude and longitude are derived from the city/region/country tuple they reside in.
Yes, they map IP to lat/long, and lat/long to city, and city to country, unless they have access to a GPS device/sensor for the exact position (+/- 1m).
The thing is, if you have an ip, you can convert that into a number (biginteger)
74.88.21.55 ==> (a.b.c.d) ==> d * 255^0 + c * 255^1 + b * 255^2 +a * 255^3 = x
then you can query a database.
All you need is a lookup-table:
T_Lookup
IP_Range_Start IP_Range_End Latitute Longitue
Then you can query like this:
SELECT Latitude, Longitude FROM T_Lookup
WHERE x BETWEEN IP_Range_Start AND IP_Range_End
Then you can calculate the distance between the two points using the haversine formula.
You can grab C code here:
http://aimbots.net/tutorials/7680-getting-country-ip-address.html
And an IP to country csv you find here:
http://ip-to-country.webhosting.info/node/view/6
Apps that display the locations of users relative to other users generally gather their data from either GPS data or IP address location data.
This Wiki article provides a nice explanation of geolocation.
They use the Galactic Coordinate system, which does in fact use longitude, l, and latitude, b.
http://en.wikipedia.org/wiki/Galactic_coordinate_system

How to get nearby location on google maps give a lat and lng coordinates

I wish to know how to get nearby location over a certain range of radius.
For example I have location of stores data stored in the database, and I want to search for a coffee over a range of 25 radius or 40 radius or even more, from a given lat and lng coordinate and then display them with their various distance from this lat and lng coordinate. I saw an example on Google but it's not working.
I would do the requested app as follows , i realize there are other ways to do it, i try:
would first go to Google code playground and get sample for the geo location.
rewrite the java script function so that it takes the longitude and latitude as parameters.
include the html file in your project , then create a webbrowser control in your csharp app.
then call the navigate to local page which will launch the page with the given longitude and latitude
You may use iFreeTools Creator - an online database app builder over Google App Engine - to store and search the geo-location database.
For a step-by-step guide on how you can do this, refer to the following blog post..
Building a Store Locator type Google Maps app over GAE, using iFreeTools
// Disclosure : I wrote code for this web-app.

Resources