Well here is what i set out to do.
Basically have users to enter a Start and an End Location.
this is then calculaated to get local searches and then put through
the direction function
So in short:
function setDirections(fromAddress, toAddress) {
gFirstSearch.execute(fromAddress);
first = gFirstSearch.results[0];
gSecondSearch.execute(toAddress);
second = gSecondSearch.results[0];
gdir.load("from: " + (first.lat + ", " + first.lng) + " to: " +
(second.lat + ", " + second.lng));
//gdir.load("from: " + (first.lat + ", " + first.lng) +" to:
London");
return false;
}
All works fine andit calculates perfectly. Exept get this i Have to
click the Get Direction Button Twice for it to work.
I figured out its the execute command that is doing it. Assoon as i
take those out the directions are calculated in one click
look here for demo:
http://connectairport.co.uk/testmap.php
And yes i have return false. By this time i have but return false
every where it is posible just to see if its a stacking issue. Please
Look at the full of my Below Code for further understanding:
//<![CDATA[
google.load('search', '1');
google.load('maps', '2');
var map;
var gdir;
var gFirstSearch;
var gSecondSearch;
var first;
var second;
function OnLoad(){
if (GBrowserIsCompatible()) {
map = new GMap2(document.getElementById("map"));
map.setCenter(new GLatLng(52.037366,-0.703726), 12);
gdir = new GDirections(map);
GEvent.addListener(gdir, "load", onGDirectionsLoad);
GEvent.addListener(gdir, "error", handleErrors);
}
gFirstSearch = new google.search.LocalSearch();
gFirstSearch.setCenterPoint(map);
//gFirstSearch.setSearchCompleteCallback(null, FirstSearch);
gSecondSearch = new google.search.LocalSearch();
gSecondSearch.setCenterPoint(map);
//gSecondSearch.setSearchCompleteCallback(null, SecondSearch);
}
function setDirections(fromAddress, toAddress) {
gFirstSearch.execute(fromAddress);
first = gFirstSearch.results[0];
gSecondSearch.execute(toAddress);
second = gSecondSearch.results[0];
gdir.load("from: " + (first.lat + ", " + first.lng) + " to: " +
(second.lat + ", " + second.lng));
//gdir.load("from: " + (first.lat + ", " + first.lng) +" to:
London");
return false;
}
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_UNAVAILABLE_ADDRESS) <---
Doc bug... this is either not defined, or Doc is wrong
// alert("The geocode for the given address or the route for the
given directions query cannot be returned due to legal or contractual
reasons.\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(){
document.getElementById("title").innerHTML = gdir.getDistance().html;
//document.getElementById("from").value = fromAddString;
// and yada yada yada...
}
google.setOnLoadCallback(OnLoad, true);
//]]>