Connecting Tech Pros Worldwide Forums | Help | Site Map

Google Map

colleen1980@gmail.com
Guest
 
Posts: n/a
#1: Jun 27 '08
Hi: I try to follow the instruction using google map in javascript.
Script some times work fine but when i put the values in Your Address
Textbox it wont shows the directions. Other than that if i put the
city state and zip it works. Can any one please tell me what i make
mistake in the script?

Thanks.

SCRIPT

----------

<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/
Quote:
>
<title>Google Maps JavaScript API Example</title>
<script src="http://maps.google.com/maps?
file=api&amp;v=2&amp;key=ABQIAAAAWjFPi89UG-
Rb3Who5FDkhRTvPROrRtr9Yene2irq6Hi48Jt9RRRSOu-klp9Mhib3eBbvZWu0LxSZjQ"
type="text/javascript"></script>
<script type="text/javascript">

//<![CDATA[

var map;

function load() {
if (GBrowserIsCompatible()) {
map = new GMap2(document.getElementById("map"));
map.setCenter(new GLatLng(37.4419, -122.1419), 13);
}
}
//]]>

function buttonOnClick()
{
var fromaddress ;
var myaddress;
var query;
// build the callers address string
fromaddress = document.getElementById("youraddress").value + ',' +
document.getElementById("yourcity").value +',' +
document.getElementById("yourstate").value +',' +
document.getElementById("yourazip").value ;
myaddress = '1521 Straight Path, Wyandanch, NY 11798';
query = fromaddress + " to " + myaddress;
document.getElementById("query").innerHTML = query;
var dirPanel = document.getElementById("directions1")
directions = new GDirections(map, dirPanel ); // make a direction
thing
directions.load(query); // make the route

}

</script>
<body onload='load();' onunload="GUnload()">
<br>
<table>
<tr>
<td>Your Address:</td>
<td><input type='text' id='youraddress'></td>
</tr>
<tr>
<td>Your City:</td>
<td><input type='text' id='yourcity'></td>
</tr>
<tr>
<td>Your State:</td>
<td><input type='text' size='2' id='yourstate'></td>
</tr>
<tr>
<td>Your Zip Code:</td>
<td><input type='text' size='5' id='yourazip'></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input type='button' value='Display Route'
onclick='buttonOnClick();'></td>
</tr>
</table>
<center><a href="index.html">Back to Home Page</a></center>
<br>
<center>
<div id="map" style="width: 500px; height: 300px" ></div>
<div id="query" &nbsp; </div>
</center>
<div id="directions1" style="width: 500px; height: 300px" ></div>
</body>
</html>


McKirahan
Guest
 
Posts: n/a
#2: Jun 27 '08

re: Google Map


<colleen1980@gmail.comwrote in message
news:3df3a5e3-ca65-422d-aef9-e99a599c9f6b@a23g2000hsc.googlegroups.com...
Quote:
Hi: I try to follow the instruction using google map in javascript.
Script some times work fine but when i put the values in Your Address
Textbox it wont shows the directions. Other than that if i put the
city state and zip it works. Can any one please tell me what i make
mistake in the script?
Are you also "Comacho"? Or are you asking a new question?

What instructions did you follow? Post the URL.

Google Maps needs more than just a street address which
is why it works when you put in a city, state, and zip.

The least you need is a zip code (or city and state).

Why does your initial map show Palo Alto, California which
is unrelated to your address in New York?


Thomas 'PointedEars' Lahn
Guest
 
Posts: n/a
#3: Jun 27 '08

re: Google Map


McKirahan wrote:
Quote:
Why does your initial map show Palo Alto, California which
is unrelated to your address in New York?
Because the route to the end point in New York is only computed when the
buttonOnClick() method containing this address is executed (through the
`onclick' attribute of the `input' element below).

Palo Alto, CA, was the location of the first Google offices, which therefore
the Google Maps API example code sets the map center to. See the
GMap2::setCenter() call in load(), called through the `onload' attribute of
the `body' element.

(On a side note, it is good to see that the example code uses the standards
compliant approach.)


PointedEars
--
Use any version of Microsoft Frontpage to create your site.
(This won't prevent people from viewing your source, but no one
will want to steal it.)
-- from <http://www.vortex-webdesign.com/help/hidesource.htm>
Closed Thread