Solved

address\postcode distance calculaton- CF

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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

Suggested Solutions

When it comes to showing a 404 error page to your visitors, you do not want that generic page to show, and you especially do not want your hosting provider’s ad error page to show either. In this article, I will show you how to enable the custom 40…
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 …
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…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

713 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