Main Menu




browser lang:en

Users Area

Client Login

today cache size is:0

 

 


Comments

fg
16/04/2011 by fdg
Hi all
13/02/2011 by
John
24/07/2010 by John
better
16/04/2010 by bob
attached files not working !
05/11/2009 by Adnan
Tuvok
14/02/2009 by
Nice script
07/02/2009 by desaj
Other solutions
07/02/2009 by Mike

Read More »


RAPIDQ

Rapid-Q:The lost files
My old library where i have collected all the rapidq scripts and italian help


Today my pagerank is: Free Page Rank Tool
Upbooking - free booking engine

PHP - calculating distance between two points

Because of the near-spherical shape of the Earth, calculating an accurate distance between two points requires the use of spherical geometry [1], and trigonometric math functions. For many applications, an approximate distance calculation provides sufficient accuracy with much less complexity.

To calculate an approximate distance in miles, we could do:
v sqrt(x * x + y * y)

where:

x = 69.1 * (lat2 - lat1) and y = 53.0 * (lon2 - lon1)


We can improve the accuracy, by adding the cosine math function:

sqrt(x * x + y * y)

where:

x = 69.1 * (lat2 - lat1) and y = 69.1 * (lon2 - lon1) * cos(lat1/57.3)


If you need greater accuracy, you can use the Great Circle Distance Formula [2]. This formula requires use of spherical geometry, and a high level of floating point mathematical accuracy - about 15 digits of accuracy (double-precision).

To convert latitude or longitude from decimal degrees to radians, we can divide the latitude and longitude values by 180/pi, or approximately 57.29577951. The radius of the earth is assumed to be 6,378.8 kilometers, or 3,963.0 miles.

Since we are using PHP, it’s much simpler, because the deg2rad() function does this calculation for us.

If you convert all latitude and longitude values to radians before the calculation, we can use this equation:

3963.0 * arccos[sin(lat1) * sin(lat2) + cos(lat1) * cos(lat2) * cos(lon2 - lon1)] Implementing this in PHP

I implement the example with kilometers:

function getDistance($latitudeFrom, $longitudeFrom,
    $latituteTo, $longitudeTo)
{
    // 1 degree equals 0.017453292519943 radius
    $degreeRadius = deg2rad(1);
 
    // convert longitude and latitude values
    // to radians before calculation
    $latitudeFrom  *= $degreeRadius;
    $longitudeFrom *= $degreeRadius;
    $latituteTo    *= $degreeRadius;
    $longitudeTo   *= $degreeRadius;
 
    // apply the Great Circle Distance Formula
    $d = sin($latitudeFrom) * sin($latituteTo) + cos($latitudeFrom)
       * cos($latituteTo) * cos($longitudeFrom - $longitudeTo);
 
    return (6371.0 * acos($d));
}



if you want the final result to be in miles:

The radius of the earth is assumed to be 6,378.8 kilometers, or 3,963.0 miles, so you only need to change:

return (6371.0 * acos($d));

to:

return (3963.0 * acos($d));

Resources

[1]

http://en.wikipedia.org/wiki/Spherical_geometry


[2]

http://en.wikipedia.org/wiki/Great-circle_distance


Comments

fg by fdg

16/04/2011 

There is a vast community of gamers waiting for you to join their ranks on the

[url=http://www.wowgoldeuro.com]wow gold[/url]close your web browser when you are done

accessing services that require authentication!| World of Warcraft gold You can find anything

from news,| buy wow gold The most highly addictive game ever played

[url=http://www.wowgoldeuro.com]cheap wow gold[/url]|


Insert your comment

Titolo
Messaggio
Nome Utente
e-mail (se vuoi ricevere le risposte a questo post anche via mail)

Users

Videos


Scripts & Tutorials

50 necessaries php tools

25/02/2011 

PHP is one of the most widely used open-source server-side scripting languages that exist today. With over…

in:Scripts and tutorials (0 comments)

FBJS Quick Jump Menu for a FBML Facebook Platform App

15/07/2010 

In a FBML Facebook App, your quick jump menu will require a little tweak to work in FBJS…

in:Scripts and tutorials (0 comments)

How to manage your online reputation, free tools forcommunity managers

02/07/2010 

Every single day, someone, somewhere is discussing something important to your business; your brand, your executives, your…

in:Scripts and tutorials (0 comments)

PHP - The Singleton Pattern

26/11/2009 

The Singleton Pattern is one of the GoF (Gang of Four) Patterns. This particular pattern provides a…

in:Scripts and tutorials (0 comments)

PHP - calculating distance between two points

20/10/2009 

Because of the near-spherical shape of the Earth, calculating an accurate distance between two points requires the use…

in:Scripts and tutorials (1 comments)

PHP - Download file with speed limit

20/10/2009 

With this script we can limit the download speed   // local file that should be send to the client $local_file…

in:Scripts and tutorials (0 comments)

PHP - Save remote images on our server using CURL

12/10/2009 

Some hosts disabled the ini setting allow_url_fopen. This also means that the ability to easily grab images…

in:Scripts and tutorials (0 comments)

PHP - verify file existence in a local server

11/06/2009 

The act to verify if a file exists, is one of more important tasks related to files operations,…

in:Scripts and tutorials (0 comments)

Read more »


Tag Clouds


necessaries toolsFBJS Quick Jump Menu FBML Facebook Platform AppHow manage your online reputation free tools forcommunity managersPHP Singleton PatternPHP calculating distance between points Download file speed limitPHP Save remote images


Add to Technorati Favorites