Calculate distance from any address

Build your list of AccuZIP6 commands by requesting commands and sharing commands with other users

Moderators: Chrissy, Steve, Terry, Donna, Dave, Eric, MartyH, Kristen, Geoff, Vince

Post Reply
User avatar
Eric
Moderator
Posts: 1910
Joined: Tue Sep 19, 2006 3:29 pm
Contact:

Calculate distance from any address

Post by Eric » Mon Mar 12, 2007 10:02 am

This command will automatically create a new field in your database named “distance”. It will create the field as a Numeric field, 20-chars wide and 15-decimals for the ultimate precise calculation.

After pasting this command into the Command Statement Syntax window, cick Run, then close the Command window.

Pull down the View menu to List View Default to show all of your fields, then scroll to the left to see the calculation of distance in the Distance field.

All you need to do is enter the Latitude and Longitude from any address into the command and click Run.

Use the Search Editor and search on the Distance field and use the Between Two Values Option.

Code: Select all

PUBLIC com_StartLAT, com_StartLONG, com_LatFieldName, com_LongFieldName
PUBLIC com_Message

*****************************************************************************************************
* Enter the Latitude and Longitude Coordinates for the address you want to calculate
* distance FROM
com_StartLAT="42.077478"
com_StartLONG="-72.607949"

*****************************************************************************************************
* Lat and Long field names in current database
PUBLIC com_LatField, com_LongField
com_LatField="latitude_"
com_LongField="longitude_"

ON ERROR com_Message=MESSAGE()

* Convert to numeric value
PUBLIC comnLat, comnLong
comnLat=ROUND(VAL(com_StartLAT),6)/57.2958
comnLong=ROUND(VAL(com_StartLONG),6)/57.2958

* Create a Distance Field if it does not exist
ALTER TABLE (ALIAS()) ADD COLUMN distance N(20,15)
ALTER TABLE (ALIAS()) ALTER COLUMN distance N(20,15)

REPLACE ALL distance WITH ROUND(3958.75*ACOS(SIN(comnLat)*;
	SIN(VAL(&com_LatField)/57.2958)+COS(comnLat)*;
	COS(VAL(&com_LatField)/57.2958)*;
	COS(VAL(&com_LongField)/57.2958-comnLong)),15)

RELEASE com_StartLAT, com_StartLONG, com_LatFieldName, com_LongFieldName
RELEASE com_Message
RELEASE com_LatField, com_LongField
RELEASE comnLat, comnLong
Chat with an AccuZIP6 technician weekdays from 7-4 PST with AccuZIP6 Live Online Support

Post Reply