Page 1 of 1

Display a MapQuest map, optional directions

PostPosted: Fri Dec 24, 2004 7:32 pm
by Cain
I've created a global method, which takes up to eight parameters. The first four are the target address. The optional second four are the address from which you want directions.

This works for US addresses. Any suggestions for improvement would be appreciated, as always. :)

I hope this is helpful for someone else, as well. I'm using it in a solution for a company that does roofing. The salesperson, installers, inspectors and so on all need to get to the home, without a lot of writing down directions for one another.

I created a form method that offers the user either a map, directions from the office, or directions from the installer (3d party contractor) office, then calls this method with the appropriate parameters.

Enjoy!

-----------------

Code: Select all
address1 = arguments[0];
city1 = arguments[1];
state1 = arguments[2];
zip1 = arguments[3];
if (!arguments[4])
{
   urlString = 'http://mapquest.com/maps/map.adp?countrycode=250&country=US&address=';
   urlString += '&address=';
   urlString += utils.stringReplace(address1, ' ', '+');
   urlString += '&city=';
   urlString += utils.stringReplace(city1, ' ', '+');
   urlString += '&state=';
   urlString += utils.stringReplace(state1, ' ', '+');
   urlString += '&zip=';
   urlString += utils.stringReplace(zip1, ' ', '+');
   urlString += '&submit.x=33&submit.y=15&addtohistory='
}
else
{
   address2 = arguments[4];
   city2 = arguments[5];
   state2 = arguments[6];
   zip2 = arguments[7];
   urlString = 'http://www.mapquest.com/directions/main.adp?go=1&do=nw&un=m&cl=EN&ct=NA&rsres=1&1y=US&';
   urlString += '1a=';
   urlString += utils.stringReplace(address2, ' ', '+');
   urlString += '&1c=';
   urlString += utils.stringReplace(city2, ' ', '+');
   urlString += '&1s=';
   urlString += utils.stringReplace(state2, ' ', '+');
   urlString += '&1z=';
   urlString += utils.stringReplace(zip2, ' ', '+');
   urlString += '&1ah=';
   urlString += '&2y=US';
   urlString += '&2a=';
   urlString += utils.stringReplace(address1, ' ', '+');
   urlString += '&2c=';
   urlString += utils.stringReplace(city1, ' ', '+');
   urlString += '&2s=';
   urlString += utils.stringReplace(state1, ' ', '+');
   urlString += '&2z';
   urlString += utils.stringReplace(zip1, ' ', '+');
   urlString += '2ah='
}
application.showURL(urlString);

PostPosted: Fri Jan 14, 2005 3:53 am
by bobcart
Nice contribution, Cain. Thank you.

PostPosted: Fri Jan 14, 2005 5:41 am
by Westy
This really is cool. I don't know how I missed this when it was first posted. I must have been too busy during the holidays. Works great. Thank you!

PostPosted: Fri Jan 14, 2005 6:03 pm
by Westy
Caution: There appears to be an omission in the above code that could result in loss of data. Be sure to add "var " in front of address1, city1, state1, zip1, address2, city2, state2, zip2. Otherwise, if you have fields of the same name you may end up overwriting your data.

PostPosted: Fri Jan 14, 2005 6:11 pm
by pbakker
Declaring a variable without var makes it a global variable, allthough this is not the proper way of doing it and it is not supported.

I guess your problem lies in the fact that you declare a variable with the same name as on of the columns in your foundset. Thus they map and if you put something into, what you thing is a variable, it actually goes into the equally named field of the selected record in your foundset.

paul

PostPosted: Fri Jan 14, 2005 6:36 pm
by Westy
Exactly. Good clarification. However, I still like and appreciate the code. I was just giving a word of caution.

PostPosted: Fri Jan 14, 2005 9:34 pm
by IT2Be
This works great!

Take out the countrycode and replace country='US' with whatever country and it works for other countries too...

Thanks for the tip!!!