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 #171330 is a reply to message #171327] Thu, 30 December 2010 12:31 Go to previous messageGo to previous message
me is currently offline  me
Messages: 192
Registered: September 2010
Karma:
Senior Member
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
[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: Wed Nov 27 00:58:51 GMT 2024

Total time taken to generate the page: 0.05101 seconds