This script/web page lets you calculate Geographical distance based on Latitude and Longitude. It does not compensate for the fact that the earth is fat in the middle. It does not take into account altitude. However, it is accurate enough for most applications.
By : icandothat
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="$Content-Type" content="text/html; charset=iso-8859-1">
</head>
<?php
if( $_POST['Submit']){
$distance = distance($_POST[LAT1], $_POST[LONG1], $_POST[LAT2],$_POST[LONG2]);
}
function distance($Aa, $Ba, $Ca, $Da){
// this is just some basic error checking i'd normally put it into a seperate file but
// for the purposes of this file... well you know.
// The math for this was taken from http://mathforum.org/library/drmath/view/51711.html
$input = array($Aa, $Ba, $Ca, $Da);
foreach($input as $name){
if (ereg("[[:alpha:]]",$name)){
echo "You cannot enter letters into this function<br>\n";
die;
}
if(ereg("\.",$name)){
$dot = ".";
$pos = strpos($name, $dot);
//echo $pos." <br>\n";
if($pos > 3){
echo "The input cannot exceed more than 3 digits left of the decimal<br>\n";
die;
}
}
if($name > 365){
echo "The input cannot exceed 365 degrees <BR>\n";
die;
}
}
$A = $Aa/57.29577951;
$B = $Ba/57.29577951;
$C = $Ca/57.29577951;
$D = $Da/57.29577951;
//convert all to radians: degree/57.29577951
if ($A == $C && $B == $D ){
$dist = 0;
}
else if ( (sin($A)* sin($C)+ cos($A)* cos($C)* cos($B-$D)) > 1){
$dist = 3963.1* acos(1);// solved a prob I ran into. I haven't fully analyzed it yet
}
else{
$dist = 3963.1* acos(sin($A)*sin($C)+ cos($A)* cos($C)* cos($B-$D));
}
return ($dist);
}
?>
<body bgcolor="#FFFFFF" text="#000000">
<form name="form1" method="post" action="">
<p>Point one Lat
<input type="text" name="LAT1" value="<?=$_POST[LAT1]?>" >
Long
<input type="text" name="LONG1" value="<?=$_POST[LONG1]?>">
</p>
<p>Point two Lat
<input type="text" name="LAT2" value="<?=$_POST[LAT2]?>">
Long
<input type="text" name="LONG2" value="<?=$_POST[LONG2]?>">
</p>
<p>
<input type="submit" name="Submit" value="Submit">
</p>
</form>
<? echo "<br>distance = ".$distance." miles (as the crow flies)<br>"; ?>
</body>
</html>
| 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
developerWorks - FREE Tools! |
The IBM DB2 Deep Compression ROI tool is designed for DBA’s and IT management personnel to perform a clinical analysis of the cost savings gained from the Storage Optimization feature of DB2 9 for Linux, UNIX and Windows. The feature, also known as Deep Compression, compresses data that lies within a database by up to 80% at times. FREE! Go There Now!
|
|
|
|
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!
|
|
|
|
Hear how IBM Rational Project and Portfolio Management integrated solutions help teams put the right tools and processes in place to maximize the effectiveness and efficiency of project teams and ensure that the business vision is being executed correctly. Learn how to automate and integrate requirements prioritization, top-down project planning, communications and controls, and methodology deployment to keep your scope, costs, and schedules under control. Tackle with an end-to-end approach the management of scope and scope changes, usage of methodology to control and empower project teams, and optimization of resources to align activity costs with the overall project plan. FREE! Go There Now!
|
|
|
|
Learn to enable users to both rate existing animations and to combine existing animations into new snippets. This is the third in a series of three tutorials that chronicle the building of a site that enables collaborative discussion and animation building using Domino and OpenLaszlo. FREE! Go There Now!
|
|
|
|
WebSphere Process Server delivers a unique integration framework that simplifies existing IT resources. Often, as IT assets grow to support business demand, so too does their complexity and manageability. In this webcast, we’ll discuss how WebSphere Process Server helps deliver an SOA infrastructure that provides a common model to orchestrate, mediate, connect, map, and execute the underlying IT functions. Discover how WebSphere Process Server simplifies integration of business processes by leveraging existing IT assets as reusable services without the complexities of traditional integration methodologies. FREE! Go There Now!
|
|
|
|
Download the Rational Application Developer (RAD) v7.5 open beta code and start developing applications for the JEE5 standard which features EJB3.0, JPA, JSF 1.2, JSP 2.1 and Servlet 2.5 standards. When you use this beta you will see how you can increase developer productivity for already existing applications with improved support for refactoring, as well as adding new features to existing applications. In addition, the beta provides tooling for JD Edwards, Oracle, SAP, Siebel and PeopleSoft to improve the developer productivity with these enterprise systems. FREE! Go There Now!
|
|
|
|
Join this webcast to see how IBM Data Studio Developer and pureQuery can take the pain out of Java data access. uApplications developed using both Java and SQL have become a common requirement. Database connectivity using Java Database Connectivity (JDBC) to create an application is a multi-step tedious process, and tooling that covers both SQL and Java has been unavailable, until now. IBM Data Studio introduces the pureQuery platform: a high-performance, Java data access platform focused on simplifying the tasks of developing, managing, and optimizing database applications and services. FREE! Go There Now!
|
|
|
|
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!
|
|
|
|
Because access to government information continues to be an area of concern for many U.S. citizens with disabilities, the U.S. government enacted Section 508 of the Rehabilitation Act in 2001 to ensure that government agencies create accessible Web content, enabling all citizens to access the information they need. A fully accessible Web site makes Web content accessible to all individuals, including those with disabilities, who may be accessing Web content via a variety of user agents. Common user agents include standard Web browsers, text-only browsers, assistive devices and mobile devices such as cell phones or personal digital assistants (PDAs). FREE! Go There Now!
|
|
|
|
The discipline of assembling and delivering software is maturing beyond standard developer-centric compile/test software builds. The end-to-end software development lifecycle is emerging as the new focus moves “Beyond the Build.” Join this on demand webcast to learn about methods for streamlining software delivery and key capabilities of the IBM Rational Build Forge framework for automating build and release management in environments of any size. FREE! Go There Now!
|
|
|
|
All FREE IBM® developerWorks Tools! |