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 = "";
   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?
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.


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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

In my daily work (mainly using, I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (, we'll extend the program by adding a depth-…
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…

776 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