views:

664

answers:

1

I am creating an application with Geo Proximity Search capability using PHP as server scripting language and MySQL as Databse.

Consider a situation:

Where we have certain set of objects having latitude and longitude positions assosciated with respective objects. On specifying location details like country and/or city along with range/radius in KM we are getting objects that are lying withing that radius/range using MySQL query for example:

"SELECT [columns] FROM [column] WHERE 1=1 AND 3963.191 * ACOS((SIN(PI() * [latitude] / 180) * SIN(PI() * [column].latitude / 180)) + (COS(PI() * [latitude] /180) * cos(PI() * [column].latitude / 180) * COS(PI() * [column].longitude / 180 - PI() * [longitude] / 180)) ) <= 10"

Above calculations will give the objects that are within the 10 KM area from the country/city center point on earth.

Now suppose i have one object (with latitude and longitude) which is not in this 10 KM area, but for example 15 KM from the country/city center point on earth. This object has service range 10 KM (giving service upto 10 KM area).

Now the question is if i am looking for the objects within the 10 KM range from country/city center point then the object (15 KM apart from country/city center point) having service range 10 KM should also be included in search.

How can i make it possible? I have country/city center lat, long coordinates,range/radius(in which we have to find out objects) and object having delivery radius (for e.g.10 KM) and its corresponding coordinates.

Can you guide me how to do that using PHP, MySQL?

+2  A: 

Use MySQL spatial extensions http://dev.mysql.com/doc/refman/5.1/en/spatial-extensions.html

On the other hand, if you want just to identify other circles that intersect with given one, they would be all of these, for which distance between centers of the circle is less then sum of radius. In other words, assuming that your original point and range is given by triple (x0,y0,r0), you need all (xn,yn,rn) for which

√((x0 - xn)² + (y0 - yn)²) ≤ r0 + rn

vartec
This may require change in existing database schema. Is there any other method?
Asif
old school geometry. I've added the formula.
vartec
Hi Vartec,Thanx for prompt reply. I have edited my question so you can provide me better solution is such scenario.Thanx in advance.
Asif
Well, basically you already have the left side, and in the right side in your formula you only have r<sub>0</sub>. You'd want to add r<sub>n</sub> ([column].range?). In other words, instead of <= 10, <= 10 + [column].range. If range is always 10km, well the just <= 20.
vartec