Solved

address\postcode distance calculaton- CF

Posted on 2003-11-13
2
288 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Get HTML5 Certified

Want to be a web developer? You'll need to know HTML. Prepare for HTML5 certification by enrolling in July's Course of the Month! It's free for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In our day to day coding, how many times have we come across a necessity to check whether a URL is a broken link or not? For those of you that answered countless and are using ColdFusion like myself, then this article is for you.  It will show yo…
Meet the world's only “Transparent Cloud™” from Superb Internet Corporation. Now, you can experience firsthand a cloud platform that consistently outperforms Amazon Web Services (AWS), IBM’s Softlayer, and Microsoft’s Azure when it comes to CPU and …
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

631 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