Just inquiring if anybody has created a site with some "distance logic" contained in it. For example, I have a list of people with their addresses (street,city, & zip) in a database. I would like to know the people that are 1 mile away from person X. Is this possible, if so how is it done. _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
On Aug 29, 2005, at 13:01, Eladio B. Caritos II wrote:> Just inquiring if anybody has created a site with some "distance > logic" contained in it. For example, I have a list of people with > their addresses (street,city, & zip) in a database. I would like to > know the people that are 1 mile away from person X. Is this possible, > if so how is it done.On http://geourl.org/ I do it with SQL (from MySQL) that''s not entirely unlike this: select s.id, acos(cos(s.latitude) * cos(s.longitude) * cos ( ? ) * cos( ? ) + cos(s.latitude) * sin(s.longitude) * cos ( ? ) * sin( ? ) + sin(s.latitude) * sin( ? ) ) * 6371 as distance, s.latitude, s.longitude, from sites s where MBRContains(GeomFromText(?),s.location) having distance IS NULL or distance <= ? order by distance, title For the GeomFromText parameter I have some code that calculates a polygon roughly the right size for the distance I want. The "* 6371" number needs to be a little different if you want miles instead of kilometer. sites.location is a "point" column in MySQL and the latitude and longitude are stored as radial degrees in "double" columns. mysql> select AsText(location), latitude, longitude from sites limit 1; +-----------------------------+-------------------+-------------------+ | AsText(location) | latitude | longitude | +-----------------------------+-------------------+-------------------+ | POINT(34.103608 -118.32681) | 0.595220246409478 | -2.06519242788175 | +-----------------------------+-------------------+-------------------+ - ask -- http://www.askbjoernhansen.com/
you need to use a geocode tool to get the longitude and latitude of the people by using their address/zip information. You can then plug this information into google maps. I am not sure though if google maps can return the "distance" thru some sort of javascript call back though. check out the google maps API. Since they do driving directions this may be possible, since directions know the distance between 2points. adam On Aug 29, 2005, at 4:01 PM, Eladio B. Caritos II wrote:> Just inquiring if anybody has created a site with some "distance > logic" contained in it. For example, I have a list of people with > their addresses (street,city, & zip) in a database. I would like to > know the people that are 1 mile away from person X. Is this possible, > if so how is it done. > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Eladio B. Caritos II <ecaritos@...> writes:> > Just inquiring if anybody has created a site with some "distance > logic" contained in it. For example, I have a list of people with > their addresses (street,city, & zip) in a database. I would like to > know the people that are 1 mile away from person X. Is this possible, > if so how is it done. > > _______________________________________________ > Rails mailing list > Rails@... > http://lists.rubyonrails.org/mailman/listinfo/rails >Eladio - Here''s the basics on how I know how to do it: For each address, you need the geocode of the address (latitude/longitude). Then, you can run a query such as this (this works in mysql): select p.* from people p ((3963.0 * acos(sin(p.latitude/57.2958) * sin(?/57.2958) + cos(p.latitude/57.2958) * cos(?/57.2958) * cos(?/57.2958 - p.longitude/57.2958))) < ?) for the parameters (?): 1 and 2 - you pass in the latitude of the center point of where you want to begin your search. 3 is the longitude of the center point of your search 4 is the distance (in miles) that you want your search to encompass. So, in the above query, if I have a table of "people" that each has a longitude and latitude, I can pass in the center point of my city, Highland UT, which is 40.419001,-111.792121 (lat/long) and the distance of, say, 5 miles. This will then query all of the people in the people table and return everyone within 5 miles of the center of Highland UT. In rails you can do People.find_by_sql(thequeryabove, lat,lat,longitude,distance) to return an array of People objects. If you need geocoding of the addresses, you can visit my website http://www.geocodeamerica.com to try it out. I have some examples in Ruby/Rails to use a webservice to do the geocoding of the addresses. Hope that helps Dave
The math is hairy but well-documented if you have latitudes and longitudes for calculating "air miles". "Street miles" is a whole nutha'' thing. :) Eladio B. Caritos II wrote:> Just inquiring if anybody has created a site with some "distance > logic" contained in it. For example, I have a list of people with > their addresses (street,city, & zip) in a database. I would like to > know the people that are 1 mile away from person X. Is this possible, > if so how is it done. > >------------------------------------------------------------------------ > >_______________________________________________ >Rails mailing list >Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >http://lists.rubyonrails.org/mailman/listinfo/rails > >-- M. Edward (Ed) Borasky http://www.borasky-research.net/ http://borasky-research.blogspot.com/ http://pdxneurosemantics.com http://pdx-sales-coach.com http://algocompsynth.com
this would involve mapping out the addresses and getting the length. ie: find and use a webservice like google maps or mapquest (if it has webservices) there is no standard on sovling how far 2 addresses are apart, and no simple method to use either. On 8/29/05, Eladio B. Caritos II <ecaritos-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Just inquiring if anybody has created a site with some "distance > logic" contained in it. For example, I have a list of people with > their addresses (street,city, & zip) in a database. I would like to > know the people that are 1 mile away from person X. Is this possible, > if so how is it done. > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > >-- Zachery Hostens <zacheryph-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Yes, I''ve done it, based on the "centers" of zip codes. My solution was to put the great circle distance calculation in database queries, since my zip/lat/long information was in a table. On Aug 29, 2005, at 1:01 PM, Eladio B. Caritos II wrote:> Just inquiring if anybody has created a site with some "distance > logic" contained in it. For example, I have a list of people with > their addresses (street,city, & zip) in a database. I would like to > know the people that are 1 mile away from person X. Is this possible, > if so how is it done. > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >