Code for putting Mapquest search on your site.

Talk about HTML resources, styles etc.
Post Reply

Would you use this map feature on your site?

Yes, Absolutely
3
50%
Yes, if it works outside of the US
1
17%
No, I don't have a need for it
2
33%
No, I don't like the code
0
No votes
No, it didn't work for me
0
No votes
 
Total votes: 6

UberM
tabulator
Posts: 15
Joined: Sat Feb 28, 2004 10:19 pm
Location: Georgia, USA

Code for putting Mapquest search on your site.

Post by UberM » Wed Mar 10, 2004 3:24 am

I would like to start off by saying that I like GoStats so much I willing to help others using it by giving everyone some code I've worked with. Thanks rchmura for such a great service!!
Here go's a slightly long piece of code BUT I think that it would/could be very beneficial to some people. The code allows you to put mapquest directions on your site.
What makes this special/cool is that you code in the destination to say your office/home/meeting/bar/grocery store/local strip club ;) or what ever. Then who ever comes to your site can just plug in there starting address and Mapquest does the rest!
The main code you have to change is about 21 lines down. It starts with window.open (this opens another webpage with the direction results) on this line you will put the destination address. Depending on your scerrn resolution the code in the window is broken to wrap around on the page. Make sure you put the line that starts with window.open ends with toolbar, scrollbars',true);
It is important to know that you MUST use %20 in place of any "spaces" that you normally have and &2c= in place of any commas"," in an address. In this code I have given the address to a local charity/outreach program as an example (Hands on Atlanta).
(I guess it is a shameless plug for people to get out and help others in need.) The address is 1605 Peachtree St NE Atlanta,GA 30309 and the code looks like this: 1605%20Peachtree%20St%20NE&2c=Atlanta&2s=GA&2z=30309&2y=US
This has only been tested on Win2k and WinXP running IE 6.0. I don't have a clue if this will work outside of the USA but I'll look into that another time or someone else can. I’ll also have to see how well it works with Netscape and Opera. Enjoy!! UberM

Code: Select all

<HEAD>
<!-- This goes inside the "HEAD" tag -->
<script language="JavaScript">
function GetDir(){
	var d = document.frmDirections;
	var s1a = d.ADDR_ORIGIN.value;
	var s1c = d.CITY_ORIGIN.value;
	var s1s = d.STATE_ORIGIN.value;
	if (s1a.length == 0){
		alert('Please enter a street address to map from.');
		return false;
		}
	if (s1c.length == 0){
		alert('Please enter a city.');
		return false;
		}
	if (s1s.length == 0){
		alert('Please enter a state.');
		return false
		
	}else{
		 window.open('http://www.mapquest.com/directions/main.adp?1A='+s1a+'&1C='+s1c+'&1S='+s1s+'&2a=1605%20Peachtree%20St%20NE&2c=Atlanta&2s=GA&2z=30309&2y=US&go=1', 'mapquest', 'resizable=yes, toolbar, scrollbars',true);
	}	
}
//Submit Form function
function submit(){
	if (GetDir() == true){
		document.GetDir.submit();
	}
}
</script>
<!-- End code that goes in the "HEAD" tag -->
</HEAD>



<BODY>
<!-- Mapquest Request. This goes inside the "body" tags-->
<form  ACTION="" METHOD="post" align="center" name="frmDirections">
<td width="434" valign="top" align="left"><font size="-1"><p><br>
Enter your starting location in the fields provided for complete turn-by-turn directions. Interactive driving directions provided by MapQuest. &nbsp; Visit <a href="http://www.mapquest.com">http://www.mapquest.com</a> to learn more about this service.</p>
<center><table cellspacing="0" cellpadding="0" border="0">
<tr>
    <td align="right" valign="top"><font size="-1">Starting Location:</font> </td>
    <td valign="top"> <input type="text" NAME="ADDR_ORIGIN" MAXLENGTH="30" onKeyPress="if(event.keyCode==13) GetDir();"></td>
</tr>
<tr>
    <td align="right" valign="top"><font size="-1">City:</font> </td>
    <td valign="top"> <input type="text" NAME="CITY_ORIGIN" MAXLENGTH="30" onKeyPress="if(event.keyCode==13) GetDir();"></td>
</tr>
<tr>
    <td align="right" valign="top"><font size="-1">State:</font> </td>
    <td valign="top"> <input type="text" NAME="STATE_ORIGIN" SIZE="6" MAXLENGTH ="2" onKeyPress="if(event.keyCode==13) GetDir();"></td>
</tr>
</table>
<p><A href="javascript:submit();">Calculate Directions</a></center></font></P>
</td>
</table>
<!--End Mapquest Request-->
</BODY>
If you use this please let me know. I'd love to see other people benefiting from this.

UberM
Last edited by UberM on Sun Mar 14, 2004 11:16 am, edited 1 time in total.

User avatar
rchmura
Site Admin
Posts: 2256
Joined: Sun Oct 05, 2003 9:09 pm

Post by rchmura » Wed Mar 10, 2004 5:01 am

UberM, you certainly know your stuff. Great work on this script.

Map Quest estimated that it would take me almost 15 hours to drive to that address :)

UberM
tabulator
Posts: 15
Joined: Sat Feb 28, 2004 10:19 pm
Location: Georgia, USA

<blush> Thanks for the complement

Post by UberM » Wed Mar 10, 2004 3:49 pm

Thanks for the compliment. This was a lot of effort for me to get just right. I originally had the submit function as a mouseover button but took it out to make it less complicated for others to use. I'm sure there are other ways of doing it but this is how I liked doing it. From time to time when I write something that I think others might like I'll post them. I know how frustrating it can be to want to do something and not have the resources to get it done.
Now about the 15 hours...come on down. I'll buy you a drink when you get here :)

UberM

User avatar
rchmura
Site Admin
Posts: 2256
Joined: Sun Oct 05, 2003 9:09 pm

Post by rchmura » Wed Mar 10, 2004 7:32 pm

hehehe After 15 hours of driving I'll probably need a pillow :) (or internet access to work on GoStats) :D

User avatar
braveheart007
master counter
Posts: 108
Joined: Fri Nov 14, 2003 8:52 am
Location: Scotland
Contact:

hi :)

Post by braveheart007 » Thu Mar 18, 2004 10:29 am

don't map quest copyright there stuff :shock:
or is this some sort of link generating content on others page ?
still think map quest might want some money
best regards
Ian

UberM
tabulator
Posts: 15
Joined: Sat Feb 28, 2004 10:19 pm
Location: Georgia, USA

Post by UberM » Thu Mar 18, 2004 2:45 pm

All the script does is let you pass the same variables that are passed when you use Mapquests form. I'm in no way trying to have people think they are using anything other than the Mapquest search. When you submit the form it is a Mapquest page that comes up. Basically all this does is pre-populate the destination address. The rest of the code was really just formatting.
I hope that anyone using this gives full credit to Mapquest. It’s a great service and I support them.

UberM

herlmysa
web counter beginner
Posts: 1
Joined: Tue Mar 20, 2012 5:00 am

Re: Code for putting Mapquest search on your site.

Post by herlmysa » Wed Mar 21, 2012 6:18 am

Is Netscape browser still a viable option with all the new browsers out there? Lots of people talk about Chrome and Safari and Firefox. What happened to Netscape? They used to be at or near the top of the list of good browsers, and it just seems like they've dropped off the face of the earth.

Post Reply