FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Calculate the distance between 2 points
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: Calculate the distance between 2 points [message #171378 is a reply to message #171330] Fri, 31 December 2010 02:13 Go to previous messageGo to previous message
The Natural Philosoph is currently offline  The Natural Philosoph
Messages: 993
Registered: September 2010
Karma:
Senior Member
Bill Braun wrote:
> On 12/30/2010 7:15 AM, Denis McMahon wrote:
>> On 30/12/10 00:43, Sarah wrote:
>>> I know this
>>>
>>> $distanceValue =
>>> rad2deg(acos(sin(deg2rad($LATITUDINE1))*sin(deg2rad($LATITUDINE2))
>>> +cos(deg2rad($LATITUDINE1))*cos(deg2rad($LATITUDINE2))*cos(deg2rad($LONGITU DINE1-
>>>
>>> $LONGITUDINE2))))*69.09;
>>>
>>> or something like this.... but I don't want to have all records of DB
>>> and than analize them one by one .... I want a query the return only
>>> nearest values
>>
>> Then you have to do the calculation as part of the query.
>>
>> What you can do is pre-calculate some latitude and longitude limits, for
>> example 1 degree of latitude always equates to the same distance north
>> to south.
>>
>> Polar circumference is 40,008 km, half that is 20,004 km, divide by 180
>> degrees, and you get 111.13333 km per degree of latitude. So, to make it
>> easy, for every 100 km of distance that you want to limit to, you only
>> need to check +- 1 degree of latitude of your given point (a more
>> precise figure is 0.9 degrees).
>>
>> Therefore, if you're checking for places within 300km, you can
>> immediately dismiss anywhere that's more than 3 (or 2.7) degrees of
>> latitude away from your specified location.
>>
>> Longitude is trickier, because the distance per degree of longitude
>> varies from 111.3222222 miles at the equator to 0 miles at the pole.
>
> It may be possible to develop a non-linearity table with would produce a
> correction factor for every X degrees of longitude, and store that in
> the database as LONGADJ or the like. It would be as accurate as it is
> detailed. A preliminary calculation would take the declining distance
> per degree of longitude into account, and the result of that calculation
> would be carried forward for the rest of the equation.
>
> Bill B
Of you want to find the closest, and don't care about the exaxct
distance, and exclude polar regions, you can simply find all longitude
offsets less than root 2 time s the smallest longitude offset, and do
the same with latitude, and that will give you a very small set and if
you have enough points, you can dis regard the sphericity and use plane
geometry.

should be a pretty fast 2 pas alogorithm through all the data with very
little maths to do.
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Checking equal number of <div> and </div>
Next Topic: extract variable from an array
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sat Nov 23 11:00:14 GMT 2024

Total time taken to generate the page: 0.05286 seconds