Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

classic asp, javascript and google map

Posted on 2011-09-02
Last Modified: 2012-06-21
I have the following codes to connect google map direction.
And now I would like to allow use to type from/to address, city, state, and zip
so it will work dynamic. Can expert help me how to do it with the following codes?


<script type="text/javascript">
    var map;
    var gdir;
    var geocoder = null;
    var addressMarker;
    function initialize() {
      if (GBrowserIsCompatible()) {      
        map = new GMap2(document.getElementById("map_canvas"));
        gdir = new GDirections(map, document.getElementById("directions"));
        GEvent.addListener(gdir, "addoverlay", onGDirectionsLoad);
        GEvent.addListener(gdir, "error", handleErrors);
        setDirections("28409", "28403", "en_US");
    function setDirections(fromAddress, toAddress, locale) {
      gdir.load("from: " + fromAddress + " to: " + toAddress,
                { "locale": locale });
    function handleErrors(){
   if (gdir.getStatus().code == G_GEO_UNKNOWN_ADDRESS)
     alert("No corresponding geographic location could be found for one of the specified addresses. This may be due to the fact that the address is relatively new, or it may be incorrect.\nError code: " + gdir.getStatus().code);
   else if (gdir.getStatus().code == G_GEO_SERVER_ERROR)
     alert("A geocoding or directions request could not be successfully processed, yet the exact reason for the failure is not known.\n Error code: " + gdir.getStatus().code);
   else if (gdir.getStatus().code == G_GEO_MISSING_QUERY)
     alert("The HTTP q parameter was either missing or had no value. For geocoder requests, this means that an empty address was specified as input. For directions requests, this means that no query was specified in the input.\n Error code: " + gdir.getStatus().code);
   else if (gdir.getStatus().code == G_GEO_BAD_KEY)
     alert("The given key is either invalid or does not match the domain for which it was given. \n Error code: " + gdir.getStatus().code);
   else if (gdir.getStatus().code == G_GEO_BAD_REQUEST)
     alert("A directions request could not be successfully parsed.\n Error code: " + gdir.getStatus().code);
   else alert("An unknown error occurred.");
  function onGDirectionsLoad(){
   var poly = gdir.getPolyline();
   if (poly.getVertexCount() > 500) {
     alert("This route has too many vertices");
   var baseUrl = "http://maps.google.com/staticmap?";
   var params = [];
   params.push("center=" + map.getCenter().lat().toFixed(6) + "," + map.getCenter().lng().toFixed(6));
   var markersArray = [];
   markersArray.push(poly.getVertex(0).toUrlValue(5) + ",greena");
   markersArray.push(poly.getVertex(poly.getVertexCount()-1).toUrlValue(5) + ",greenb");
   params.push("markers=" + markersArray.join("|"));
   var polyParams = "rgba:0x0000FF80,weight:5|";
   var polyLatLngs = [];
   for (var j = 0; j < poly.getVertexCount(); j++) {
     polyLatLngs.push(poly.getVertex(j).lat().toFixed(5) + "," + poly.getVertex(j).lng().toFixed(5));
   params.push("path=" + polyParams + polyLatLngs.join("|"));
   params.push("zoom=" + map.getZoom());
   var img = document.createElement("img");
   img.src = baseUrl + params.join("&") + "&key=key";
   document.getElementById("staticMapIMG").innerHTML = "";
   document.getElementById("staticMapURL").innerHTML = baseUrl + params.join("&") + "&key=key";
Question by:Webboy2008
  • 5
  • 3
LVL 29

Expert Comment

ID: 36476047
From where does this data come now?

Author Comment

ID: 36476070
from/to address should be entered by the users.
the map need to be shown on the webpage
LVL 29

Expert Comment

ID: 36476079
Right, but how is the data passed in now?
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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.


Author Comment

ID: 36476130
now is set in the code setDirections("28409", "28403", "en_US");
LVL 29

Accepted Solution

Badotz earned 500 total points
ID: 36476238
Create <input> fields on your page for the values, then create a function that invokes
setDirections(fromAddress, toAddress, locale)

Open in new window

after getting the values from the user's input.

Author Comment

ID: 36476245

I am not javascript coder, can you put them in codes. thanks
LVL 29

Expert Comment

ID: 36476395
function map_it(e) {
    // It is assumed that the HTML elements are <input> elements,
    // and that they have an ID that corresponds to the names in quotes in the
    // following three statements
    var fromAddress = document.getElementById("txtFromAddress").value;
    var toddress = document.getElementById("txtToAddress").value;
    var locale = document.getElementById("txtLocale").value;
    // Invoke the function
    setDirections(fromAddress, toAddress, locale);

Open in new window

LVL 29

Expert Comment

ID: 36491804
The strong, silent type, eh?

No worries - glad to help.

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

792 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