Solved

address\postcode distance calculaton- CF

Posted on 2003-11-13
2
282 Views
Last Modified: 2013-12-24
Is it possible to Calculate distance (and possibly direction)  between a user specified address\postcode and an address\postcode in my database using coldfusion and one of the map-services like Mapquest or Yahoo Map?  I would like to send information to one of these sites and get the results back without using my own zipfind DB.

For example,
http://www.ups.com/using/services/locate/locate.html

but doesn't have to be as detailed as this.

I would greatly appreciate your help on this.

Thank you,

-RVV
0
Comment
Question by:RVV1
  • 2
2 Comments
 
LVL 15

Accepted Solution

by:
danrosenthal earned 125 total points
ID: 9742182
check this out....

<CFSET state1      = "CA">
<CFSET zip1       = "90210">
<CFSET country1 = "US">

<CFSET state2      = "NY">
<CFSET zip2       = "10101">
<CFSET country2 = "US">

<CFSET searchstring = "go=1&do=nw&ct=NA">
<CFSET searchstring = searchstring & "&1y=#country1#&1a=&1c=&1s=#state1#&1z=#zip1#&1ah=">
<CFSET searchstring = searchstring & "&2y=#country2#&2a=&2c=&2s=#state2#&2z=#zip2#&2ah=">

<CFHTTP url="http://www.mapquest.com/directions/main.adp?#searchstring#"></cfhttp>

<CFSET result = cfhttp.filecontent>
<CFSET start = FINDNOCASE("Total Distance:",result)>
<CFSET end = FINDNOCASE("miles",result,start+1)>

<CFIF val(start) AND val(end) AND end gt start>
      <CFSET distance = REREPLACENOCASE(MID(result,start,end-start),"[^0-9]*([0-9,.]*).*","\1","ALL")>
      <CFOUTPUT>
      Distance: #distance# miles
      </cfoutput>
<CFELSE>
      Distance not found
</cfif>
0
 
LVL 15

Expert Comment

by:danrosenthal
ID: 9742208
You can search for address also, but if it doesn't find an exact match, you won't get a distance...


<CFSET addr1       = "">
<CFSET city1       = "">
<CFSET state1      = "CA">
<CFSET zip1       = "90210">
<CFSET country1 = "US">

<CFSET addr2      = "">
<CFSET city2      = "">
<CFSET state2      = "NY">
<CFSET zip2       = "10101">
<CFSET country2 = "US">

<CFSET searchstring = "go=1&do=nw&ct=NA">
<CFSET searchstring = searchstring & "&1y=#country1#&1a=#addr1#&1c=#city1#&1s=#state1#&1z=#zip1#&1ah=">
<CFSET searchstring = searchstring & "&2y=#country2#&2a=#addr2#&2c=#city2#&2s=#state2#&2z=#zip2#&2ah=">

<CFHTTP url="http://www.mapquest.com/directions/main.adp?#searchstring#"></cfhttp>

<CFSET result = cfhttp.filecontent>
<CFSET start = FINDNOCASE("Total Distance:",result)>
<CFSET end = FINDNOCASE("miles",result,start+1)>

<CFIF val(start) AND val(end) AND end gt start>
      <CFSET distance = REREPLACENOCASE(MID(result,start,end-start),"[^0-9]*([0-9,.]*).*","\1","ALL")>
      <CFOUTPUT>
      Distance: #distance# miles
      </cfoutput>
<CFELSE>
      Distance not found
</cfif>
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This is a guide to setting up a new WHM/cPanel Server to be used for web hosting accounts. It is intended for web hosting company administrators and dedicated server owners. For under $99 per month (considering normal rate of Big Data Cetnters like …
A web service (http://en.wikipedia.org/wiki/Web_service) is a software related technology that facilitates machine-to-machine interaction over a network. This article helps beginners in creating and consuming a web service using the ColdFusion Ma…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now