Tip

Zip Code Distance Calculation

I've developed a Formula language and LotusScript version of the formula to
calulate the distance between two zip codes in the US. The Formula language
version is included below.

There are several subscription zip code services available that will make
available a list of all valid zip codes in the country. You can arrange to
have the location of the zip code included in the file. The zip code itself is
great for validating data entry, but there are other ways to use the
information once it is 'in house'. To use this example:

1. Add the code below to a view action button in a database of zip codes.
2. Select one zip code in a view.
3. Click on the button and select a second zip code from the list.
4. See the distance between zip codes.

The script version has been great for calculating the closest vendor for a
company to work with and many similar applications.

Note: I have a small freely distributable DB of zip codes that I could include
with this example code to make it work out of the box.

Take a look and let me know what you think.
Andy
ziplist := @DbColumn("";"":"";"ZipCode";1);
zipToUse := @Prompt([OKCANCELLIST]; "Select a Zip Code"; "Select a zip code to
calculate distance from the selected zip."; "";ziplist);
zipRLat := @DbLookup("":"Cache" ; ""; "ZipCode"; zipToUse; "RadLatitude");
zipRLong := @DbLookup("":"Cache" ; ""; "ZipCode"; zipToUse; "RadLongitude");
zipCity := @DbLookup("":"Cache" ; ""; "ZipCode"; zipToUse; "City");
zipState := @DbLookup("":"Cache" ; ""; "ZipCode"; zipToUse; "State");
RadLat2 := zipRLat;
RadLong2 := zipRLong;

CalcX :=
(@Sin(RadLatitude) * @Sin(RadLat2) + @Cos(RadLatitude) *
@Cos(RadLat2) * @Cos(@Abs(RadLong2 - RadLongitude)));

RadDist := @ATan(-CalcX / @Sqrt(-CalcX * CalcX + 1)) + 2 * @ATan(1);
DistMI := RadDist * 3958.754;
RndDistMI := @If(DistMi = 0;0;@Integer(DistMI * 10)/10);
@Prompt([OK];"Miles"; "Distance: " + @Text( RndDistMI) + " miles. From " +
City + ", " + State + " to " + zipCity + ", " + zipState + ".")

This was first published in November 2000

There are Comments. Add yours.

 
TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.