Miscellaneous Code
  Home arrow Miscellaneous Code arrow Calculate Distance Between Two ZIP Cod...
Codewalker Forums 
  Tutorials  
Database Articles  
Miscellaneous  
Navigation Usability  
PEAR Articles  
Programming Basics  
Server Administration  
XML Tutorials  
  Reviews  
Database Book Reviews  
Linux Book Reviews  
Miscellaneous Reviews  
PHP Book Reviews  
PHP Software Reviews  
Server Admin Reviews  
SQL Tool Reviews  
  Code Gallery  
Content Management Code  
Contest Code  
Counters Code  
Database Code  
Date Time Code  
Discussion Board Code  
Email Code  
File Manipulation Code  
GUI Code  
Link Farm Code  
Miscellaneous Code  
Search Code  
Site Navigation Code  
User Management Code  
Forums Sitemap 
Download TestComplete 
JMSL Numerical Library 
IBM® developerWorks
Weekly Newsletter 
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
MISCELLANEOUS CODE

Calculate Distance Between Two ZIP Codes
By: Codewalkers
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 2 stars2 stars2 stars2 stars2 stars / 3
    2004-07-25

    Table of Contents:

    Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Deliver dealer locator/store locator, lead generator, marketing application, or call center solution with this source code to calculate distance between zip codes by using their latitude and longitude.

    By : tgotchi

    #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
    #::: :::
    #::: This routine calculates the distance between two points (given the :::
    #::: latitude/longitude of those points). It is being used to calculate :::
    #::: the distance between two ZIP Codes or Postal Codes using our :::
    #::: ZIPCodeWorld(TM) and PostalCodeWorld(TM) products. :::
    #::: :::
    #::: Definitions: :::
    #::: South latitudes are negative, east longitudes are positive :::
    #::: :::
    #::: Passed to function: :::
    #::: lat1, lon1 = Latitude and Longitude of point 1 (in decimal degrees) :::
    #::: lat2, lon2 = Latitude and Longitude of point 2 (in decimal degrees) :::
    #::: unit = the unit you desire for results :::
    #::: where: 'M' is statute miles :::
    #::: 'K' is kilometers (default) :::
    #::: 'N' is nautical miles :::
    #::: :::
    #::: United States ZIP Code/ Canadian Postal Code databases with latitude :::
    #::: & longitude are available at http://www.zipcodeworld.com :::
    #::: :::
    #::: For enquiries, please contact sales@zipcodeworld.com :::
    #::: :::
    #::: Official Web site: http://www.zipcodeworld.com :::
    #::: :::
    #::: Hexa Software Development Center © All Rights Reserved 2004 :::
    #::: :::
    #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

    $pi = atan2(1,1) * 4;

    sub distance {
    my ($lat1, $lon1, $lat2, $lon2, $unit) = @_;
    my $theta = $lon1 - $lon2;
    my $dist = sin(deg2rad($lat1)) * sin(deg2rad($lat2)) + cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * cos(deg2rad($theta));
    $dist = acos($dist);
    $dist = rad2deg($dist);
    $dist = $dist * 60 * 1.1515;
    if ($unit eq "K") {
    $dist = $dist * 1.609344;
    } elsif ($unit eq "N") {
    $dist = $dist * 0.8684;
    }
    return ($dist);
    }

    #::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
    #::: This function get the arccos function using arctan function :::
    #::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
    sub acos {
    my ($rad) = @_;
    my $ret = atan2(sqrt(1 - $rad**2), $rad);
    return $ret;
    }

    #::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
    #::: This function converts decimal degrees to radians :::
    #::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
    sub deg2rad {
    my ($deg) = @_;
    return ($deg * $pi / 180);
    }

    #::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
    #::: This function converts radians to decimal degrees :::
    #::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
    sub rad2deg {
    my ($rad) = @_;
    return ($rad * 180 / $pi);
    }

    print distance(32.9697, -96.80322, 29.46786, -98.53506, "M") . " Miles\n";
    print distance(32.9697, -96.80322, 29.46786, -98.53506, "K") . " Kilometers\n";
    print distance(32.9697, -96.80322, 29.46786, -98.53506, "N") . " Nautical Miles\n";
    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

    More Miscellaneous Code Articles
    More By Codewalkers

     

    IBM® developerWorks developerWorks - FREE Tools!


    IBM – Taking Web 2.0 to Work

    You'll get answers to many questions and more from David Barnes, Lead Evangelist for IBM Emerging Internet Technologies. David will discuss aspects of Web 2.0 that bring value to corporations, academia, and government. He'll also discuss IBM's vision around Web 2.0, including the importance of remixability and consumability. The discussion will culminate with examples of various IBM Software Group solutions you can use to get ahead of the Web 2.0 adoption curve.
    FREE! Go There Now!


    NEW! A Layered approach to delivering security-rich Web applications

    As businesses grow increasingly dependent upon Web applications to provide services to customers, employees and partners, these complex applications become more difficult to secure. Although traditional security solutions protect Internet infrastructure layers, they do not guard against HTTP and HTML attacks. Many organizations that conduct security testing still deploy applications that allow attackers to manipulate their logic and wreak havoc on their business. To mitigate this risk, development and delivery teams must address Web application security throughout the lifecycle, addressing the many layers detailed in this paper.
    FREE! Go There Now!


    NEW! Develop Systems Software Assets with IBM Rational Asset Manager

    Join us for this on demand webcast to learn about developing complex systems more quickly and efficiently. We'll cover market drivers for developing, governing and reusing systems software assets and how you can develop system software assets with Rational Asset Manager.
    FREE! Go There Now!


    NEW! Download the free Web Application Security eKit

    Discover how IBM Rational AppScan Standard Edition can help you detext vulnerabilities in your web applications in the Web Application Security eKit. IBM Rational AppScan is a leading suite of automated web application security solutions that scan and test for common Web application vulnerabilities. The new Web Application Security eKit provides you with valuable resources, including white papers, demos, and additional information on the benefits of testing your Web applications.
    FREE! Go There Now!


    NEW! IBM Rational AppScan Standard Edition V7.7

    Secure your Web applications with IBM Rational AppScan Standard Edition V7.7, previously known as Watchfire AppScan. This Web application security testing tool automates vulnerability assessments and scans and tests for common Web application vulnerabilities. Visit IBM developerWorks to download a free trial of IBM Rational AppScan Standard Edition V7.7.
    FREE! Go There Now!


    NEW! Improve your build process with IBM Rational Build Forge, Part 2: Automate builds for a real-world Tomcat project

    Learn how Rational Build Forge can extend a simple compile and package build process by adding customization and deployment capability. Go from a manual method to automating: checking for code changes; getting the latest source; compiling and packaging; customizing; copying to and restarting a deployment server; and sending e-mail notification that a new version is available.
    FREE! Go There Now!


    NEW! Maintaining QoS and Process Integrity in an SOA Environment

    This webcast outlines the best practices that must be instituted to gain the maximum benefit from SOA while maintaining high quality of service. Whether you are deploying new applications or managing and monitoring your existing infrastructure, learn how you can ensure high quality of services with SOA based solutions from IBM. All registrants who attend this live Web Seminar will receive complimentary access to a white paper titled “Maintaining QoS in an SOA Environment”.
    FREE! Go There Now!


    NEW! Rational Talks to You:Per Kroll on Rational Method Composer Plug-in customization

    Join this Rational Talks to You teleconference on December 11 at 1:00 pm ET to get tips on building your own plugins with Rational Method Composer. Get your questions answered!
    FREE! Go There Now!


    NEW! Trial download: IBM Informix Dynamic Server Express Edition V11.0

    Informix Dynamic Server (IDS) Express Edition offers outstanding online transaction processing (OLTP) database performance, while helping to simplify and automate many of the tasks associated with deploying databases for small business applications. IDS 11 further extends the ease of management and applications integration with the Admin API and Scheduler, high availability with Continuous Log Restore for backup server recovery in case of a primary server failure, and column level encryption to protect personal and company private data.
    FREE! Go There Now!


    NEW! Whitepaper: Delivering SOA solutions: service lifecycle management

    The unprecedented scope of a service-oriented architecture (SOA) initiative brings to the forefront a number of management and governance issues that were sidestepped in the past. The key to a successful SOA implementation is managing and governing activities throughout the entire SOA delivery lifecycle by ensuring that services conform to the needs of all of the business’s stakeholders. Learn how service lifecycle management allows the business to ensure that the process by which services are defined, created, tested, deployed, optimized and retired is manageable, repeatable and auditable.
    FREE! Go There Now!



    All FREE IBM® developerWorks Tools!

    MISCELLANEOUS CODE ARTICLES

    - upload image to database sql
    - Random Password Generator
    - BCroot, get the root of a number with BC fun...
    - Find pi in a high precision
    - [PHP5] FORMCHECKER : data validation
    - SPL and ITERATOR : examples
    - Xml with Rss Feeds
    - [PHP5] NOTIMEOUT PACKAGE
    - Class to return variables to a Flash movie.
    - BCGCD Greatest Common Denominator (Large Num...
    - HMAC
    - Binary to Decimal
    - Decimal to Binary using logs
    - web.framework v1.0.0
    - Shopping Cart Class





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
    Stay green...Green IT