Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

address\postcode distance calculaton- CF

Posted on 2003-11-13
2
Medium Priority
?
292 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 500 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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 …
Lease-to-own eliminates the expenditure of hardware replacement and allows you to pay off the server over time. Usually, this is much cheaper than leasing servers. Think of lease-to-own as credit without interest.
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

886 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