RE: [PHP] Re: Google Maps Distance Between UK Postcodes

2008-09-12 Thread Boyd, Todd M.
 -Original Message-
 From: news [mailto:[EMAIL PROTECTED] On Behalf Of Colin Guthrie
 Sent: Friday, September 12, 2008 3:15 AM
 To: php-general@lists.php.net
 Subject: [PHP] Re: Google Maps Distance Between UK Postcodes
 
 Boyd, Todd M. wrote:
  -Original Message-
  From: tedd
 
  Considering that my other profession is Geophysicist, I'm kind of up
  on those sort of things. The Earth is an oblate spheroid and the
  computation to include the curvature of the earth would be a bit
 more
  involved.
 
  ---8--- snip
 
  But it's also NOT an oblate spheroid! :)
 
  http://blogs.discovermagazine.com/badastronomy/2008/09/08/ten-things-
 you
  -dont-know-about-the-earth/
 
 Todd Vs. Tedd: A deathmatch separated only by one vowel! FIIGHT!!!

Willing to bet I've lost this one already, seeing as how I've never been (and 
likely never will be) a geophysicist. :) I took an Astronomy class a few years 
ago, but I couldn't tell you what the Chandrasekhar Limit is now if my life 
depended on it. I just thought it was pretty neat that I'd read that article 
maybe two days ago, having almost never heard the word oblate or spheroid 
(let alone used together in a sentence), and tedd mentions the very same thing 
soon after. I couldn't resist the rebuttal. Heh...


Todd Boyd
Web Programmer





RE: [PHP] Re: Google Maps Distance Between UK Postcodes

2008-09-12 Thread tedd

At 3:54 PM -0500 9/11/08, Boyd, Todd M. wrote:

  Considering that my other profession is Geophysicist, I'm kind of up

 on those sort of things. The Earth is an oblate spheroid and the
 computation to include the curvature of the earth would be a bit more
 involved.


---8--- snip

But it's also NOT an oblate spheroid! :)

http://blogs.discovermagazine.com/badastronomy/2008/09/08/ten-things-you
-dont-know-about-the-earth/


Todd:

LOL -- Discover magazine is hardly the definitive authority for 
Geophysical terms. This is more an article written to make 
controversial claims for laymen to ponder rather than to provide 
anything of real substance for people who work in the Geophysical 
field.


Note, while the article claims that the Earth is NOT an oblate 
spheroid, it does NOT provide a real alternative. However, it does 
say it would be smoother [billiard ball] but it also claims that 
The Earth is more complicated than an oblate spheroid. So, which is 
it? Is it as simple as a billiard ball or more complicated than an 
oblate spheroid?


You see, it's one of those Hit and run -- You can't prove me wrong 
because I didn't say anything articles.


While technically the Earth isn't ANY standard/formal static size, an 
oblate spheroid is a pretty good fit.


Perhaps an example may be of assistance -- if the Earth was pure 
water (a fluid medium having an equipotential surface) then its 
surface could be described as a spheroid -- imagine a drop of water 
in space without any external forces applied to it.


If you introduce rotation, then the radius from the center of the 
Earth to the equator (perpendicular to the axis of spin) expands and 
the radius at the poles (axis of spin) reduces. As such, this surface 
IS known and IS defined as an oblate spheroid -- and with respect to 
Earth, this IS upon which the geodetic latitude determinations are 
made.


Now, to be more exact in describing the Earth's surface, requires 
more attention to detail.


First, the Earth consists of more than just water and it's content 
are not uniform with respect to distribution and density -- not to 
mention numerous other physical properties (i.e., elasticity);


Second, the Earth has rotational, orbital, and even processional 
forces applied to it;


Third, the Earth has external gravitational forces exerted on it from 
the Sun, Moon, Planets, and et all;


Considering all, the surface of the Earth becomes very complex to 
compute, let alone to define for the general population.


So, the problem of what term to use to define the surface of the 
Earth really depends upon the audience you're addressing. If I were 
talking to a group of preschoolers, I would use the term Ball, but 
if I was addressing a group of Geophysical Scientist, then I would 
use the term oblate spheroid. Incidentally, I have done both 
successfully without objection.


An oblate spheroid is good enough for me, but the author of the 
article likes the term Ball -- each has their audience of believers.


Cheers,

tedd

--
---
http://sperling.com  http://ancientstones.com  http://earthstones.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: Google Maps Distance Between UK Postcodes

2008-09-12 Thread tedd

At 8:31 AM -0700 9/11/08, mike wrote:

On Thu, Sep 11, 2008 at 8:17 AM, tedd [EMAIL PROTECTED] wrote:


 Considering that my other profession is Geophysicist, I'm kind of up on
 those sort of things. The Earth is an oblate spheroid and the computation to
 include the curvature of the earth would be a bit more involved.


what do you think of the code i mentioned earlier?

$distance = number_format(ceil(69*rad2deg(acos(sin(deg2rad($ulat)) *
sin(deg2rad($vlat)) + cos(deg2rad($ulat)) * cos(deg2rad($vlat)) *
cos(deg2rad($ulong - $vlong));

where:

$ulat = latitude of user #1
$ulong = longitude of user #1

$vlat = latitude of user #2
$vlong = longitude of user #2

I took the very popular mysql query (at the time) that supposedly
works with a sphere and mapped it to php functions and it has appeared
to work very well. I have only tested with US zip codes, but the
concept should be the same as long as lat/long are centered properly.


I dunno.

But I do know that knowing the latitude and longitude of two points 
on the surface of the Earth and then trying to calculate the actual 
distance between each is not a trivial task


Take a look at:

http://en.wikipedia.org/wiki/Latitude#Degree_length

In that table you can see that for every degree north-south there is 
a change -- likewise, for every degree east-west AND those changes 
are not equal.


This has been a problem for map makers for a long time.

I remember surveying ancient playas (i.e., lake-beds) in the Mohave 
desert where my rod man would travel away and I would see his boots 
disappear beneath the curvature of the Earth. Now, what's the 
distance between me and my rod man? Is it the distance I see in my 
survey instrument or the distance of my rod chain? One is a straight 
line while the other isn't -- which is the correct one?


Cheers,

tedd

--
---
http://sperling.com  http://ancientstones.com  http://earthstones.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: Google Maps Distance Between UK Postcodes

2008-09-11 Thread Jason Pruim


On Sep 11, 2008, at 11:19 AM, tedd wrote:


At 5:37 PM +0100 9/1/08, Colin Guthrie wrote:

Tom Chubb wrote:
That's all way above my head, but I think I'll be able to  
understand it

after a strong coffee!


I should point out that this is really just trig and is only an  
approximate distance as the crow flies. Not even sure if it takes  
the curvature of the earth into consideration, but it's probably  
good enough for most things.


Oh, I forgot to add -- I use it for this:

http://php1.net/b/zipcode/

This plugs into a zip code dB that has the center of the zip code in  
lats and longs.


Cheers,

tedd



In regards to your php1.net/b/zipcode/ ... I think I may have found a  
bug :) zipcode 49422 does not show up as being within 10 miles of  
49424 even though 49423 does. FYI, 49422 is the zipcode for holland,  
mi PO BOXES so I'm not sure if your database has that included or  
not...  Or where they would even register the lat/lon... I would  
assume at the holland post office.. but I could be wrong.



--

Jason Pruim
Raoset Inc.
Technology Manager
MQC Specialist
11287 James St
Holland, MI 49424
www.raoset.com
[EMAIL PROTECTED]





--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: Google Maps Distance Between UK Postcodes

2008-09-11 Thread mike
On Thu, Sep 11, 2008 at 8:17 AM, tedd [EMAIL PROTECTED] wrote:

 Considering that my other profession is Geophysicist, I'm kind of up on
 those sort of things. The Earth is an oblate spheroid and the computation to
 include the curvature of the earth would be a bit more involved.

what do you think of the code i mentioned earlier?

$distance = number_format(ceil(69*rad2deg(acos(sin(deg2rad($ulat)) *
sin(deg2rad($vlat)) + cos(deg2rad($ulat)) * cos(deg2rad($vlat)) *
cos(deg2rad($ulong - $vlong));

where:

$ulat = latitude of user #1
$ulong = longitude of user #1

$vlat = latitude of user #2
$vlong = longitude of user #2

I took the very popular mysql query (at the time) that supposedly
works with a sphere and mapped it to php functions and it has appeared
to work very well. I have only tested with US zip codes, but the
concept should be the same as long as lat/long are centered properly.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: Google Maps Distance Between UK Postcodes

2008-09-11 Thread Nathan Rixham

tedd wrote:

At 5:37 PM +0100 9/1/08, Colin Guthrie wrote:

Tom Chubb wrote:

That's all way above my head, but I think I'll be able to understand it
after a strong coffee!


I should point out that this is really just trig and is only an 
approximate distance as the crow flies. Not even sure if it takes the 
curvature of the earth into consideration, but it's probably good 
enough for most things.


Oh, I forgot to add -- I use it for this:

http://php1.net/b/zipcode/

This plugs into a zip code dB that has the center of the zip code in 
lats and longs.


Cheers,

tedd



I've got code to cal all of this it's rather simple actually - I'll fire 
it through when i get back from work.


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Re: Google Maps Distance Between UK Postcodes

2008-09-11 Thread Boyd, Todd M.
 -Original Message-
 From: tedd [mailto:[EMAIL PROTECTED]
 Sent: Thursday, September 11, 2008 10:17 AM
 To: php-general@lists.php.net
 Subject: [PHP] Re: Google Maps Distance Between UK Postcodes
 
 At 5:37 PM +0100 9/1/08, Colin Guthrie wrote:
 Tom Chubb wrote:
 That's all way above my head, but I think I'll be able to understand
 it
 after a strong coffee!
 
 I should point out that this is really just trig and is only an
 approximate distance as the crow flies. Not even sure if it takes
 the curvature of the earth into consideration, but it's probably
 good enough for most things.
 
 
 I've reviewed your code and it does not include the curvature of the
 earth -- it's a flat surface computation.
 
 Considering that my other profession is Geophysicist, I'm kind of up
 on those sort of things. The Earth is an oblate spheroid and the
 computation to include the curvature of the earth would be a bit more
 involved.

---8--- snip

But it's also NOT an oblate spheroid! :)

http://blogs.discovermagazine.com/badastronomy/2008/09/08/ten-things-you
-dont-know-about-the-earth/


Todd Boyd
Web Programmer




--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: Google Maps Distance Between UK Postcodes

2008-09-01 Thread Tom Chubb
On 01/09/2008, Colin Guthrie [EMAIL PROTECTED] wrote:

 Tom Chubb wrote:

 I thought it would be easy but it seems that I need to convert each
 postcode
 to Lat/Long using Geocoding and then work it out from there.


 That's the best way: then just do something like:

 Here's how I do it in SQL, but the principle is the same in PHP, so I'm
 sure you'll be able to convert it.

 HTHs

 Col

 snip
  public static function Distance($latA, $lngA, $latB, $lngB, $blnMiles =
 false)
  {
$multiplier = 6371;
if ($blnMiles)
  $multiplier *= 1.609344;

$rv = ESQL
  (ACOS(
SIN(RADIANS($latA)) * SIN(RADIANS($latB))
+ COS(RADIANS($latA)) * COS(RADIANS($latB)) * COS(RADIANS($lngB) -
 RADIANS($lngA)))
  * $multiplier)
 ESQL;
return $rv;
  }
 /snip




 --

 Colin Guthrie
 gmane(at)colin.guthr.ie
 http://colin.guthr.ie/

 Day Job:
  Tribalogic Limited [http://www.tribalogic.net/]
 Open Source:
  Mandriva Linux Contributor [http://www.mandriva.com/]
  PulseAudio Hacker [http://www.pulseaudio.org/]
  Trac Hacker [http://trac.edgewall.org/]


 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php



Thanks Colin,
That's all way above my head, but I think I'll be able to understand it
after a strong coffee!
Any idea how you get the co-ords from the UK Postcode though?
There seems to be a privacy factor with UK postcodes, but I'm only after the
first section: eg SW11 6**


Re: [PHP] Re: Google Maps Distance Between UK Postcodes

2008-09-01 Thread Michal Sokolowski
2008/9/1 Tom Chubb [EMAIL PROTECTED]

 On 01/09/2008, Colin Guthrie [EMAIL PROTECTED] wrote:
 
  Tom Chubb wrote:
 
  I thought it would be easy but it seems that I need to convert each
  postcode
  to Lat/Long using Geocoding and then work it out from there.
 
 
  That's the best way: then just do something like:
 
  Here's how I do it in SQL, but the principle is the same in PHP, so I'm
  sure you'll be able to convert it.
 
  HTHs
 
  Col
 
  snip
   public static function Distance($latA, $lngA, $latB, $lngB, $blnMiles =
  false)
   {
 $multiplier = 6371;
 if ($blnMiles)
   $multiplier *= 1.609344;
 
 $rv = ESQL
   (ACOS(
 SIN(RADIANS($latA)) * SIN(RADIANS($latB))
 + COS(RADIANS($latA)) * COS(RADIANS($latB)) * COS(RADIANS($lngB) -
  RADIANS($lngA)))
   * $multiplier)
  ESQL;
 return $rv;
   }
  /snip
 
 
 
 
  --
 
  Colin Guthrie
  gmane(at)colin.guthr.ie
  http://colin.guthr.ie/
 
  Day Job:
   Tribalogic Limited [http://www.tribalogic.net/]
  Open Source:
   Mandriva Linux Contributor [http://www.mandriva.com/]
   PulseAudio Hacker [http://www.pulseaudio.org/]
   Trac Hacker [http://trac.edgewall.org/]
 
 
  --
  PHP General Mailing List (http://www.php.net/)
  To unsubscribe, visit: http://www.php.net/unsub.php
 
 

 Thanks Colin,
 That's all way above my head, but I think I'll be able to understand it
 after a strong coffee!
 Any idea how you get the co-ords from the UK Postcode though?
 There seems to be a privacy factor with UK postcodes, but I'm only after
 the
 first section: eg SW11 6**



This address should help you. Thay have distance calculator on the page but
also you can download database with postcodes and their co-ords -
http://www.pc-i.co.uk/postcode-distance.php


Re: [PHP] Re: Google Maps Distance Between UK Postcodes

2008-09-01 Thread mike
This is what I have:

$distance = number_format(ceil(69*rad2deg(acos(sin(deg2rad($ulat)) *
sin(deg2rad($vlat)) + cos(deg2rad($ulat)) * cos(deg2rad($vlat)) *
cos(deg2rad($ulong - $vlong));

where:

$ulat = latitude of user #1
$ulong = longitude of user #1

$vlat = latitude of user #2
$vlong = longitude of user #2

it seems to work properly at least with US data. I assume any
longitude/latitude date will work fine with it. If anyone has links to
other countries' zipcode mappings I'd love to be able to add that to
my site :)

(I basically took a MySQL query and mapped it to the PHP functions)

On 9/1/08, Tom Chubb [EMAIL PROTECTED] wrote:

  snip
   public static function Distance($latA, $lngA, $latB, $lngB, $blnMiles =
  false)
   {
 $multiplier = 6371;
 if ($blnMiles)
   $multiplier *= 1.609344;
 
 $rv = ESQL
   (ACOS(
 SIN(RADIANS($latA)) * SIN(RADIANS($latB))
 + COS(RADIANS($latA)) * COS(RADIANS($latB)) * COS(RADIANS($lngB) -
  RADIANS($lngA)))
   * $multiplier)
  ESQL;
 return $rv;
   }

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: Google Maps Distance Between UK Postcodes

2008-09-01 Thread Tom Chubb
On 01/09/2008, Michal Sokolowski [EMAIL PROTECTED] wrote:



 2008/9/1 Tom Chubb [EMAIL PROTECTED]

  On 01/09/2008, Colin Guthrie [EMAIL PROTECTED] wrote:
 
  Tom Chubb wrote:
 
  I thought it would be easy but it seems that I need to convert each
  postcode
  to Lat/Long using Geocoding and then work it out from there.
 
 
  That's the best way: then just do something like:
 
  Here's how I do it in SQL, but the principle is the same in PHP, so I'm
  sure you'll be able to convert it.
 
  HTHs
 
  Col
 
  snip
   public static function Distance($latA, $lngA, $latB, $lngB, $blnMiles =
  false)
   {
 $multiplier = 6371;
 if ($blnMiles)
   $multiplier *= 1.609344;
 
 $rv = ESQL
   (ACOS(
 SIN(RADIANS($latA)) * SIN(RADIANS($latB))
 + COS(RADIANS($latA)) * COS(RADIANS($latB)) * COS(RADIANS($lngB) -
  RADIANS($lngA)))
   * $multiplier)
  ESQL;
 return $rv;
   }
  /snip
 
 
 
 
  --
 
  Colin Guthrie
  gmane(at)colin.guthr.ie
  http://colin.guthr.ie/
 
  Day Job:
   Tribalogic Limited [http://www.tribalogic.net/]
  Open Source:
   Mandriva Linux Contributor [http://www.mandriva.com/]
   PulseAudio Hacker [http://www.pulseaudio.org/]
   Trac Hacker [http://trac.edgewall.org/]
 
 
  --
  PHP General Mailing List (http://www.php.net/)
  To unsubscribe, visit: http://www.php.net/unsub.php
 
 


 Thanks Colin,
 That's all way above my head, but I think I'll be able to understand it
 after a strong coffee!
 Any idea how you get the co-ords from the UK Postcode though?
 There seems to be a privacy factor with UK postcodes, but I'm only after
 the
 first section: eg SW11 6**



 This address should help you. Thay have distance calculator on the page but
 also you can download database with postcodes and their co-ords -
 http://www.pc-i.co.uk/postcode-distance.php




That's perfect for what I need! Thanks very much Michal

Tom