News
How
to Build a Dealer Location Query
By Bud Walker
Locator lookup programs allow you to provide a
valuable, time-saving service to your customers and
prospects, by phone, or from your Website. Using the
ZIP Data interface in Melissa Datas Address Object
and your dealer database, you can quickly give your
inquirer a list of the sites they are looking for
that are closest to them, including distance in
miles.
Typically, there are two types of resolution that
can be achieved with a Dealer Locator application.
One is based on the 5-digit ZIP Code, and the other
is based on the ZIP+4 Code and provides a higher
resolution when multiple locations occur in the same
ZIP Code. Depending on your needs, Melissa Data
provides the Address Object for ZIP Code searches,
or the GeoCoder Object for the finer ZIP+4 searches.
Aside from the obvious benefits of good data
quality, the Melissa Data Address Object has many
other functions to help you leverage your investment
and build enterprise tools that solve common
problems like radius searches and nearest location
queries.
Calculate Bearing and Distance functions within the
Object make it easy to implement this functionality
into your custom applications.
The Melissa Data Address Object has four interfaces
available to the programmer: Verify Address, Zip
Data, Parse, and Street Data. The following steps
will enable you to benefit from the Dealer Locator
methods of the ZipData interface.
Before you can create your dealer locator you must
prepare a dealer database. (You must have a dealer
database in order to utilize this solution.)
1. Append the latitude & longitude to each record in
your dealer database by performing the following
steps:
Pass the ZIP Code into the FindZip method of the
ZipData interface of the Address Object
Retrieve the latitude & longitude from the
latitude & longitude properties and write them back
to your dealer database.
You are now ready to build your dealer locator.
1. Retrieve and store the latitude & longitude of
the ZIP Code you wish to locate the nearest dealer.
This can be done using the FindZip method located in
the ZipData interface.
2. Create a distance variable and set it to 10000.
3. Create a dealer variable.
4. Create a loop to do the following until your
dealer database reaches EOF
Retrieve the latitude & longitude from the dealer
record
Pass the stored lat/long & the just retrieved
lat/long into the ComputeDistance method.
If the distance returned is less then the value in
your distance variable then replace the value in
your distance variable with the value retrieved from
the ComputeDistance method and store the dealer in
your dealer variable.
Repeat the loop until your dealer database reaches
EOF.
5. You should now have your closest dealer.
So in recap your logic should look like this:
Variables
--ZIP Code to build radius around--
zipIn = 92688
--Distance--
dist = 10000
--Input ZIP Codes latitude & longitude--
latIn = 0
longIn = 0
--Comparing latitude & longitude--
ckLat = 0
ckLong = 0
Logic
--Get the latitude & longitude of the input ZIP
Code--
object.FindZip(zipIn)
latIn = object.Latitude
longIn = object.Longitude
Do while Dealer database is EOF (End Of File)
--Retrieve dealer lat & long--
ckLat = dealer.lat
ckLong = dealer.long
--Calculate distance--
result = Object.ComputeDistance(latIn, longIn, ckLat,
ckLong)
--Compare to stored distance--
if(result<dist)
--Save new distance and dealer info--
dist = result
end if
--Get next record and repeat loop--
Hopefully this will help you to easily create a
Dealer Locator for use in your custom applications.
Any questions or comments are welcome.
--- Bud Walker is a product manager for Melissa
Data.
|
|
|