Here's my code, simple enough:
<html>
<head>
<script type='text/javascript' src='
http://www.google.com/jsapi?key=ABQIAAAAoN9kM0QqONCLIWU4yHeIJhSgG_jKAmzdssu2U-M8Edy2G0i_1hSCzKKxGUYV0SPXEMkIwZR4qQPugQ'><
/script>
<script type='text/javascript'>
//<![CDATA[
google.load('maps', '2');
var gdir2;
var gdir37;
var gdir140;
var gdir225;
function load() {
if (GBrowserIsCompatible()) {
gdir2 = new google.maps.Directions();
google.maps.Event.addListe
ner(gdir2,
'load', handleLoad);
gdir2.load('from: 413 Old Ithaca Road Horseheads NY 14845 to: 79 Spencer Rd,Candor,NY 13743', {getSteps: true});
gdir37 = new google.maps.Directions();
google.maps.Event.addListe
ner(gdir37
, 'load', handleLoad);
gdir37.load('from: 413 Old Ithaca Road Horseheads NY 14845 to: 305 Grant Ave 1,Endicott,NY 13760', {getSteps: true});
gdir140 = new google.maps.Directions();
google.maps.Event.addListe
ner(gdir14
0, 'load', handleLoad);
gdir140.load('from: 413 Old Ithaca Road Horseheads NY 14845 to: RT 23 ,Norwich,NY 13815', {getSteps: true});
gdir225 = new google.maps.Directions();
google.maps.Event.addListe
ner(gdir22
5, 'load', handleLoad);
gdir225.load('from: 413 Old Ithaca Road Horseheads NY 14845 to: 30 South Broad St 1,Norwich,NY 13464', {getSteps: true});
}
}
function handleLoad(){
document.getElementById('2
').innerHT
ML=gdir2.g
etDistance
().html;
document.getElementById('3
7').innerH
TML=gdir37
.getDistan
ce().html;
document.getElementById('1
40').inner
HTML=gdir1
40.getDist
ance().htm
l;
document.getElementById('2
25').inner
HTML=gdir2
25.getDist
ance().htm
l;
}
window.onload = load;
</script>
</head>
<body>
855520939<br />
<b>Side Hill Acres Goat Farm</b><br />79 Spencer Rd<br />Candor,NY 13743
<div id='2'>...</div><br>
<b>Down to Earth Whole Foods</b><br />305 Grant Ave, 1<br />Endicott,NY 13760
<div id='37'>...</div><br>
<b>Evans Farmhouse and Creamery</b><br />RT 23 <br />Norwich,NY 13815
<div id='140'>...</div><br>
<b>Solstice Whole Foods and Herbs</b><br />30 South Broad St, 1<br />Norwich,NY 13464
<div id='225'>...</div><br>
Done!
</body>
</html>
It runs fine and updates all DIVs w/ accurate distances, but the Browser consistently gives a gdir140.getDistance().html
is null or not an object error on line 38, which is the " document.getElementById('2
25').inner
HTML=gdir2
25.getDist
ance().htm
l;" line in my handleLoad function.
In the end, this is all to be a hidden function in between when a user types in an address and sees a list of addresses sorted by distance (nearest to farthest). My plan is to put the distance data in a temporary dB table (probably named using the SessionID) and then load it to the "Results" page from the dB (very, very easy). I know I could use a client-side array or something like that, but my way will work, too...I just gotta solve this Javascript error thing first.
Thanks!
Start Free Trial