Solved

classic asp, javascript and google map

Posted on 2011-09-02
8
405 Views
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?

Thanks

<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");
     return;
   }
   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());
   params.push("size=310x400");
   var img = document.createElement("img");
   img.src = baseUrl + params.join("&") + "&key=key";
   document.getElementById("staticMapIMG").innerHTML = "";
   document.getElementById("staticMapIMG").appendChild(img);
 
   document.getElementById("staticMapURL").innerHTML = baseUrl + params.join("&") + "&key=key";
}
    </script>
0
Comment
Question by:Webboy2008
  • 5
  • 3
8 Comments
 
LVL 29

Expert Comment

by:Badotz
Comment Utility
From where does this data come now?
0
 

Author Comment

by:Webboy2008
Comment Utility
from/to address should be entered by the users.
the map need to be shown on the webpage
0
 
LVL 29

Expert Comment

by:Badotz
Comment Utility
Right, but how is the data passed in now?
0
 

Author Comment

by:Webboy2008
Comment Utility
now is set in the code setDirections("28409", "28403", "en_US");
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 29

Accepted Solution

by:
Badotz earned 500 total points
Comment Utility
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.
0
 

Author Comment

by:Webboy2008
Comment Utility
Badotz,

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

Expert Comment

by:Badotz
Comment Utility
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

0
 
LVL 29

Expert Comment

by:Badotz
Comment Utility
The strong, silent type, eh?

No worries - glad to help.
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
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…

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now