NYCPHP Meetup

NYPHP.org

[nycphp-talk] Hello / Geo coords

Spot spot at deviantart.com
Thu Nov 20 23:57:48 EST 2003


Ah, wonderful. Thank you Daniel.

Unfortunately the zip code solution is not going to work for us (as hoped). About 45% of our traffic is non-US/Canada.

This code will be very helpful.


Thank you again.

Spot
  ----- Original Message ----- 
  From: Daniel Kushner 
  To: NYPHP Talk 
  Sent: Thursday, November 20, 2003 9:54 PM
  Subject: RE: [nycphp-talk] Hello / Geo coords


  Spot,

  Here's some code that I have from a long time ago that calculates the distance between airports based on longitude and latitude. You can do the same with Zip codes once you convert a zip code to long/lat.

  Best,
  Daniel Kushner

  $db = new My_DB("SELECT * 
        FROM airports AS a 
           WHERE id IN ('$origin', '$destination')");
   
   $db->next_record();
   $a = deg2rad($db->f('latitude'));
   $b = deg2rad($db->f('longitude'));
   $origin_id = $db->f('id');
   $origin_name = $db->f('name');
   
   $db->next_record();
   $c = deg2rad($db->f('latitude'));
   $d = deg2rad($db->f('longitude'));
   $destination_id = $db->f('id');
   $destination_name = $db->f('name');
   

   $r=3963.1; //radius of the earth in miles

   //calculate the distance between the two points
   $distance = acos(
        (cos($a) * cos($b) * cos($c) * cos($d)) + 
        (cos($a) * sin($b) * cos($c) * sin($d)) + 
        (sin($a) * sin($c))
       ) * $r;
       
   if($origin == $destination) {
    echo "Distance = 0<br>"; 
   } else {
    echo "Origin: ($origin_id) $origin_name<br>";
    echo "Destination: ($destination_id) $destination_name<br>";
    echo "Distance in miles: ", round($distance,4), "<br>";
    echo "Distance in kilometers: ", round(($distance*1.609),4), "<br>";
   }
    -----Original Message-----
    From: talk-bounces at lists.nyphp.org [mailto:talk-bounces at lists.nyphp.org]On Behalf Of Spot
    Sent: Thursday, November 20, 2003 2:56 PM
    To: talk at lists.nyphp.org
    Subject: [nycphp-talk] Hello / Geo coords


    Hey everyone,

    Just thought I would introduce myself as new member to the list and pose a question at the same time.

    My name is Spot(yes, legally). I am with deviantART.com. We are the largest art community in the world with a little under 500,000 artists, almost 3 million pieces of art and close to 80 million hits a month. We move about 55mbit/s average. Running on 37 boxes (last I checked) and two 9 terabyte fibre enclosures. All on Apache/PHP/Mysql. Except for Zues talking to the fibre enclosures for raw data (images). All of our code is from the ground up. No external libraries.

    Currently we are employing somewhat of a locational system where we allow artists to provide their Geo coords (after getting them from Maporama.com) and then, currently using GeoURL.org, we pull in RSS feeds and allow them to see lists of artists close to them.

    We are interested in bringing as much of this "in-house" as possible. Especially the GeoURL functionality. Does anyone have any information on methods for creating "crow flies" distances between artists based on geo coords? I would be interested in using a third party library if there is one.


    Thanks!

    Spot
    Director of Prints
    deviantART Inc.
    www.deviantart.com


------------------------------------------------------------------------------


  _______________________________________________
  talk mailing list
  talk at lists.nyphp.org
  http://lists.nyphp.org/mailman/listinfo/talk

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.nyphp.org/pipermail/talk/attachments/20031120/bf188119/attachment.html>


More information about the talk mailing list