Solved

address\postcode distance calculaton- CF

Posted on 2003-11-13
2
287 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

Save the day with this special offer from ATEN!

Save 30% on the CV211 using promo code EXPERTS30 now through April 30th. The ATEN CV211 connects a laptop directly to any server allowing you instant access to perform data maintenance and local operations, for quick troubleshooting, updating, service and repair.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Splitting up a coldfusion site into 2 separate sites in IIS 3 109
System Analysis 5 72
http to https 3 83
Adding multiple JVM environments to RedHat 6 7 83
Have you ever sent email via ColdFusion and thought of tracking this mail to capture the exact date and time when the message was opened ?  If yes, then this article is for you ! First we need a table user_email with columns user_id , email , sub…
Most ColdFusion developers get confused between the CFSet, Duplicate, and Structcopy methods of copying a Structure, especially which one to use when. This Article will explain the differences in the approaches with examples; therefore, after readin…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
Suggested Courses

759 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