#### Do you have a question? Post it now! No Registration Necessary. Now with pictures!

## Re: Calculate the distance between 2 points

I know this

$distanceValue =

rad2deg(acos(sin(deg2rad($LATITUDINE1))*sin(deg2rad($LATITUDINE2))

+cos(deg2rad($LATITUDINE1))

$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

$distanceValue =

rad2deg(acos(sin(deg2rad($LATITUDINE1))*sin(deg2rad($LATITUDINE2))

+cos(deg2rad($LATITUDINE1))

***cos(deg2rad($LATITUDINE2))***cos(deg2rad($LONGITUDINE1-$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

## Re: Calculate the distance between 2 points

Seems like your model needs to eat a lots of cookies or even cache some res=

ults :P

This will be a hudge amount of data so you better think about some algorith=

m to divide and conquer your problem. For example build a subset:

If you are in (Lat/Long) 35=B0 18' S 149=B0 7' E and want to find ONE neare=

st point then first take a look around and get everything that is 35 S 149 =

E. If there are more than get more detailled. Otherwise spread more. And so=

on.

This rectangle around your pos might speed up your algorithm, because only =

a small subset left over to deal with.

ults :P

This will be a hudge amount of data so you better think about some algorith=

m to divide and conquer your problem. For example build a subset:

If you are in (Lat/Long) 35=B0 18' S 149=B0 7' E and want to find ONE neare=

st point then first take a look around and get everything that is 35 S 149 =

E. If there are more than get more detailled. Otherwise spread more. And so=

on.

This rectangle around your pos might speed up your algorithm, because only =

a small subset left over to deal with.

## Re: Calculate the distance between 2 points

On 12/29/2010 8:23 PM, Thomas 'PointedEars' Lahn wrote:

+cos(deg2rad($LATITUDINE1))*cos(deg2rad($LATITUDINE2))*cos(deg2rad($LONGITUDINE1-

It seems to be the time of year, or possibly the lunar cycle, for

bullies to crawl out from under their rocks. Is this place the meeting

ground of choice for miserable people?

You can express an opinion in decent, respectful language. But crude and

insulting behavior gets no pass from me.

Dial it down, Pointed Ears.

Bill B

+cos(deg2rad($LATITUDINE1))*cos(deg2rad($LATITUDINE2))*cos(deg2rad($LONGITUDINE1-

It seems to be the time of year, or possibly the lunar cycle, for

bullies to crawl out from under their rocks. Is this place the meeting

ground of choice for miserable people?

You can express an opinion in decent, respectful language. But crude and

insulting behavior gets no pass from me.

Dial it down, Pointed Ears.

Bill B

## Re: Calculate the distance between 2 points

On 12/29/2010 8:42 PM, Bill Braun wrote:

Bill, ignore "pointed head". That's just how he is. If he had to wait

until he had an intelligent answer, he wouldn't be able to post anything.

--

==================

Remove the "x" from my email address

Jerry Stuckle

JDS Computer Training Corp.

jstucklex@attglobal.net

==================

Bill, ignore "pointed head". That's just how he is. If he had to wait

until he had an intelligent answer, he wouldn't be able to post anything.

--

==================

Remove the "x" from my email address

Jerry Stuckle

JDS Computer Training Corp.

jstucklex@attglobal.net

==================

## Re: Calculate the distance between 2 points

Bill Braun wrote:

No. its the time of year when thick students who haven't done their

coursework expect someone else to do it for them.

No, its a place where people who should have listened to lectures, come

for answers they have actually learnt already.

And students who cheat and crib get no pass from me either.

No. its the time of year when thick students who haven't done their

coursework expect someone else to do it for them.

No, its a place where people who should have listened to lectures, come

for answers they have actually learnt already.

And students who cheat and crib get no pass from me either.

## Re: Calculate the distance between 2 points

On 12/30/2010 4:47 AM, The Natural Philosopher wrote:

Bullies, thugs, and tyrants count on reasonable people turning their

backs and letting their boorish behavior go unchecked. They are for the

most part cowards, who, when made accountable, tuck tail and run.

There is a reason, and I will complain, drawing attention to it as needed.

Bill B

Bullies, thugs, and tyrants count on reasonable people turning their

backs and letting their boorish behavior go unchecked. They are for the

most part cowards, who, when made accountable, tuck tail and run.

There is a reason, and I will complain, drawing attention to it as needed.

Bill B

## Re: Calculate the distance between 2 points

On 12/30/2010 4:37 AM, Bill Braun wrote:

No, Bill, it is necessary for TNP to belittle and demean. He needs to

feel superior to everyone else.

--

==================

Remove the "x" from my email address

Jerry Stuckle

JDS Computer Training Corp.

jstucklex@attglobal.net

==================

No, Bill, it is necessary for TNP to belittle and demean. He needs to

feel superior to everyone else.

--

==================

Remove the "x" from my email address

Jerry Stuckle

JDS Computer Training Corp.

jstucklex@attglobal.net

==================

## Re: Calculate the distance between 2 points

On 30/12/10 00:43, Sarah wrote:

+cos(deg2rad($LATITUDINE1))*cos(deg2rad($LATITUDINE2))*cos(deg2rad($LONGITUDINE1-

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.

However, you can try and calculate a "box", outside which you don't need

to calculate the actual great circle distance because it will always be

greater than the range you are specifying. You will need to be careful

if your box embraces either a pole or the equator that you don't dismiss

valid points.

What you could then do is copy all the points inside your "might fit"

box into a temporary table, and then run a query on the temporary table

to determine their actual distances. This might be less computationally

intensive than calculating the great circle range for every point.

Rgds

Denis McMahon

+cos(deg2rad($LATITUDINE1))*cos(deg2rad($LATITUDINE2))*cos(deg2rad($LONGITUDINE1-

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.

However, you can try and calculate a "box", outside which you don't need

to calculate the actual great circle distance because it will always be

greater than the range you are specifying. You will need to be careful

if your box embraces either a pole or the equator that you don't dismiss

valid points.

What you could then do is copy all the points inside your "might fit"

box into a temporary table, and then run a query on the temporary table

to determine their actual distances. This might be less computationally

intensive than calculating the great circle range for every point.

Rgds

Denis McMahon

## Re: Calculate the distance between 2 points

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

## Re: Calculate the distance between 2 points

Bill Braun wrote:

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.

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.

#### Site Timeline

- » Checking equal number of <div> and </div>
- — Next thread in » PHP Scripting Forum

- » AND in the if statement
- — Previous thread in » PHP Scripting Forum

- » URL redirection
- — Newest thread in » PHP Scripting Forum

- » Seamless SSO
- — Last Updated thread in » PHP Scripting Forum

- » Dell Battery Slice LED codes
- — The site's Newest Thread. Posted in » Laptop Computers Forum