Display a MapQuest map, optional directions

Find out how to get things done with Servoy. Post how YOU get things done with Servoy

Display a MapQuest map, optional directions

Postby Cain » Fri Dec 24, 2004 7:32 pm

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);
Cain
 

Postby bobcart » Fri Jan 14, 2005 3:53 am

Nice contribution, Cain. Thank you.
bobcart
 
Posts: 214
Joined: Fri Nov 21, 2003 8:01 pm
Location: Melbourne (AUS)

Postby Westy » Fri Jan 14, 2005 5:41 am

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!
Westy
 
Posts: 852
Joined: Fri Feb 13, 2004 5:27 am
Location: Lynnfield, Massachusetts USA

Postby Westy » Fri Jan 14, 2005 6:03 pm

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.
Westy
 
Posts: 852
Joined: Fri Feb 13, 2004 5:27 am
Location: Lynnfield, Massachusetts USA

Postby pbakker » Fri Jan 14, 2005 6:11 pm

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
pbakker
 
Posts: 2822
Joined: Wed Oct 01, 2003 8:12 pm
Location: Amsterdam, the Netherlands

Postby Westy » Fri Jan 14, 2005 6:36 pm

Exactly. Good clarification. However, I still like and appreciate the code. I was just giving a word of caution.
Westy
 
Posts: 852
Joined: Fri Feb 13, 2004 5:27 am
Location: Lynnfield, Massachusetts USA

Postby IT2Be » Fri Jan 14, 2005 9:34 pm

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!!!
Marcel J.G. Trapman (IT2BE)
SAN partner - Freelance Java and Servoy
Servoy Components - IT2BE Plug-ins and Beans for Servoy
ServoyForge - Open Source Components for Servoy
User avatar
IT2Be
Servoy Expert
 
Posts: 4766
Joined: Tue Oct 14, 2003 7:09 pm
Location: Germany


Return to How To

Who is online

Users browsing this forum: No registered users and 8 guests