Solved

classic, javascript asp google

Posted on 2011-09-02
2
266 Views
Last Modified: 2012-05-12
The attached suppose to get two from/to address that already in the codes and run the google map direction and show the page on the webpage.
for some reasons, it does not do anything and want experts helps.

Thanks
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<%
function queryString(name)
{
	var value = new String (Request.Form(name));
	return convertToString(value);
}
	
function convertToString(name)
{
	var value = new String (name);
    	var fieldValue = value.toLowerCase();
	if (fieldValue == "null" || 
		fieldValue == "undefined" || 
		fieldValue == "undefine" ||
		fieldValue == "object")
		return "";
   	else return value;
}

function formatPhone(phone)
{
	try {
	     var phone = new String (phone);
		 if (phone != "")
		 {
			var code = phone.substring(0, 3);
			return "(" + code + ") " + phone.substring(3, 6) + "-" + phone.substring(6); 
		 }  
	} catch (e) { return phone; }
}
  
function formatTitleCase(word)
{
    try {
	  	var word = new String (word);
	  	if (word != "")
	  	{
	  		var letter = word.substring(0, 1).toUpperCase();
			return letter + word.substring(1, word.length).toLowerCase();  
	  	}
	} catch (e) { return word; }
}


function getDestinationAddress(val)
{
	var pos = 0;	
	var address = new String (val);
        if (address.length > 10)
	{
		var pos = address.indexOf('AAA');
                return address.substring(pos + 3);
	}
	return val;
        
}

function getOriginAddress(val)
{
	var address = new String (val);
        if (address.length > 10)
	{
		var pos = address.indexOf('AAA');
                return address.substring(0, pos);
	}
return val;
}


%>
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <title>My Google API Application</title>
     <script type="text/javascript" src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=ABQIAAAAJxYcItOgkqR8R_oLqIOOTBQBTZKV61x1v48YJEqqfLRn8l4ZShTSK_3kHakNOTnwhzJ3mFGsv0ntTw"></script>
  <script type="text/javascript">

      var map;
      var gdir;
      var geocoder = null;
      var addressMarker;


      function initialize(from, to) {
          if (GBrowserIsCompatible()) {
              map = new GMap2(document.getElementById("map_canvas"));
              gdir = new GDirections(map, document.getElementById("directions"));
              GEvent.addListener(gdir, "load", onGDirectionsLoad);
              GEvent.addListener(gdir, "error", handleErrors);
              setDirections(from, to, "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("Error code: " + gdir.getStatus().code);
          else if (gdir.getStatus().code == G_GEO_SERVER_ERROR)
              alert("Error code: " + gdir.getStatus().code);
          else if (gdir.getStatus().code == G_GEO_MISSING_QUERY)
              alert("Error code: " + gdir.getStatus().code);
          else if (gdir.getStatus().code == G_GEO_BAD_KEY)
              alert("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() { }



    </script>
  
  </head>
  <body onunload="GUnload()">
<div id="contact"> 
<div class="contactInfo">
<p><strong>Origin:</strong><span id="origin"> <%="100 Main Street"%>&nbsp;<%="Los Angeles"%>, CA&nbsp; <%="90032"%></span></p>
<p><strong>Destination:</strong><span id="destination"> <%="100 Airport Blvd"%>&nbsp;<%="Los Angeles"%>, CA&nbsp; <%="90045"%></span></p>
</div>
<%
	  
	 
%>
<div class="clear"></div>
<div id="map_canvas"></div>
<div id="direction">
<div class="clear"></div>

</div>
</div>


<script type="text/javascript">

    try {
        $(document).ready(function () {
            var points = "1000";
            var fromAddress = document.getElementById("origin").innerHTML;
            var toAddress = document.getElementById("destination").innerHTML;
            document.getElementById("origin").innerHTML = " " + points;
            initialize(fromAddress, toAddress);

           
        });

    } catch (e) { }

</script>

  </body>
 </html>

Open in new window

0
Comment
Question by:Webboy2008
2 Comments
 
LVL 28

Accepted Solution

by:
sammySeltzer earned 500 total points
ID: 36475629
I think you confused Javascript with VBScript

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<script>
function queryString(name)
{
	var value = new String (Request.Form(name));
	return convertToString(value);
}

function convertToString(name)
{
	var value = new String (name);
    	var fieldValue = value.toLowerCase();
	if (fieldValue == "null" ||
		fieldValue == "undefined" ||
		fieldValue == "undefine" ||
		fieldValue == "object")
		return "";
   	else return value;
}

function formatPhone(phone)
{
	try {
	     var phone = new String (phone);
		 if (phone != "")
		 {
			var code = phone.substring(0, 3);
			return "(" + code + ") " + phone.substring(3, 6) + "-" + phone.substring(6);
		 }
	} catch (e) { return phone; }
}

function formatTitleCase(word)
{
    try {
	  	var word = new String (word);
	  	if (word != "")
	  	{
	  		var letter = word.substring(0, 1).toUpperCase();
			return letter + word.substring(1, word.length).toLowerCase();
	  	}
	} catch (e) { return word; }
}


function getDestinationAddress(val)
{
	var pos = 0;
	var address = new String (val);
        if (address.length > 10)
	{
		var pos = address.indexOf('AAA');
                return address.substring(pos + 3);
	}
	return val;

}

function getOriginAddress(val)
{
	var address = new String (val);
        if (address.length > 10)
	{
		var pos = address.indexOf('AAA');
                return address.substring(0, pos);
	}
return val;
}

</script>
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <title>My Google API Application</title>
     <script type="text/javascript" src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=ABQIAAAAJxYcItOgkqR8R_oLqIOOTBQBTZKV61x1v48YJEqqfLRn8l4ZShTSK_3kHakNOTnwhzJ3mFGsv0ntTw"></script>
  <script type="text/javascript">

      var map;
      var gdir;
      var geocoder = null;
      var addressMarker;


      function initialize(from, to) {
          if (GBrowserIsCompatible()) {
              map = new GMap2(document.getElementById("map_canvas"));
              gdir = new GDirections(map, document.getElementById("directions"));
              GEvent.addListener(gdir, "load", onGDirectionsLoad);
              GEvent.addListener(gdir, "error", handleErrors);
              setDirections(from, to, "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("Error code: " + gdir.getStatus().code);
          else if (gdir.getStatus().code == G_GEO_SERVER_ERROR)
              alert("Error code: " + gdir.getStatus().code);
          else if (gdir.getStatus().code == G_GEO_MISSING_QUERY)
              alert("Error code: " + gdir.getStatus().code);
          else if (gdir.getStatus().code == G_GEO_BAD_KEY)
              alert("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() { }



    </script>

  </head>
  <body onunload="GUnload()">
<div id="contact">
<div class="contactInfo">
<p><strong>Origin:</strong><span id="origin"> <%="100 Main Street"%>&nbsp;<%="Los Angeles"%>, CA&nbsp; <%="90032"%></span></p>
<p><strong>Destination:</strong><span id="destination"> <%="100 Airport Blvd"%>&nbsp;<%="Los Angeles"%>, CA&nbsp; <%="90045"%></span></p>
</div>
<%


%>
<div class="clear"></div>
<div id="map_canvas"></div>
<div id="direction">
<div class="clear"></div>

</div>
</div>


<script type="text/javascript">

    try {
        $(document).ready(function () {
            var points = "1000";
            var fromAddress = document.getElementById("origin").innerHTML;
            var toAddress = document.getElementById("destination").innerHTML;
            document.getElementById("origin").innerHTML = " " + points;
            initialize(fromAddress, toAddress);


        });

    } catch (e) { }

</script>

  </body>
 </html>

Open in new window

0
 

Author Comment

by:Webboy2008
ID: 36475672
sammySeltzer: The codes you posted does not work. It doesn't show the map and direction at all.
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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…

706 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

18 Experts available now in Live!

Get 1:1 Help Now