the code i am using is as
var map;
var gdir;
var geocoder = null;
var addressMarker;
var distance;
var directionDisplay;
var startAddress;
var endAddress;
var markerArray = [];
var stepDisplay;
// var indClose = 0;
//This function initializes the page
function initialize() {
if (GBrowserIsCompatible()) {
//map = new GMap2(document.getElementById("map_canvas"));
var myOptions = {
zoom: 7,
mapTypeId: google.maps.MapTypeId.ROADMAP,
center: "<%=strOrig%>",
mapTypeControl: true,
mapTypeControlOptions: {
style: google.maps.MapTypeControlStyle.HORIZONTAL_BAR,
position: google.maps.ControlPosition.BOTTOM
},
navigationControl: true,
navigationControlOptions: {
style: google.maps.NavigationControlStyle.ZOOM_PAN,
position: google.maps.ControlPosition.TOP_RIGHT
},
scaleControl: true,
scaleControlOptions: {
position: google.maps.ControlPosition.TOP_LEFT
}
}
map = new GMap2(document.getElementById("map_canvas"), myOptions);
gdir = new GDirections(map, document.getElementById("directions"));
GEvent.addListener(gdir, "addoverlay", afterDir);
GEvent.addListener(gdir, "error", handleErrors);
setDirections("<%=strOrig%>", "<%=strDest%>", "en_US");
calcRoute("<%=strOrig%>", "<%=strDest%>");
}
}
function afterDir() {
lstrDistance = gdir.getDistance();
document.getElementById("distance_road").innerHTML = lstrDistance.html;
}
function calcRoute(location1, location2) {
var directionsService = new google.maps.DirectionsService();
var directionsDisplay = new google.maps.DirectionsRenderer();
var start = location1;
var end = location2;
// var request = {
// origin: start,
// destination: end,
// waypoints:[{location: start}, {location: end}],
// travelMode: google.maps.DirectionsTravelMode.DRIVING,
// avoidHighways:true };
var f = document.forms[0];
// var blAvoidHighway = true;
// var blAvoidToll = true;
// if (f.chkHighWay.checked == false)
// blAvoidHighway = false;
// else
// blAvoidHighway = true;
// if (f.chkToll.checked == false)
// blAvoidToll = false;
// else
// blAvoidToll = true;
var request = {
origin: start,
destination: end,
waypoints: [{ location: start }, { location: end}],
travelMode: google.maps.DirectionsTravelMode.DRIVING,
optimizeWaypoints: false
// avoidHighways: blAvoidHighway
// avoidTolls: blAvoidToll
};
directionsService.route(request, function (response, status) {
if (status == google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(response);
var route = response.routes[0];
startAddress = route.legs[1].start_address;
endAddress = route.legs[1].end_address;
}
});
}
function setDirections(fromAddress, toAddress, locale) {
var opts = {};
var f = document.forms[0];
// if (f.chkHighWay.checked == false)
// opts.avoidHighways = false;
// else
// opts.avoidHighways = true;
var opts1 = {};
// if (f.chkToll.checked == false)
// opts1.avoidTolls = true;
// else
// opts1.avoidTolls = false;
// gdir.load("from: " + fromAddress + " to: " + toAddress,
// opts,opts1);
gdir.load("from: " + fromAddress + " to: " + toAddress,
opts);
}
function callroute() {
document.frmPage.submit();
}
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);
alert("Please enter correct Origin/Destination location");
parent.window.returnValue = "0";
window.close();
}
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);
alert("Please enter correct Origin/Destination location");
parent.window.returnValue = "0";
window.close();
}
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);
alert("Please enter correct Origin/Destination location");
parent.window.returnValue = "0";
window.close();
}
// 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);
alert("Please enter correct Origin/Destination location");
parent.window.returnValue = "0";
window.close();
}
else if (gdir.getStatus().code == G_GEO_BAD_REQUEST) {//alert("A directions
request could not be successfully parsed.\n Error code: " +
gdir.getStatus().code);
alert("Please enter correct Origin/Destination location");
parent.window.returnValue = "0";
window.close();
}
else {
alert("An unknown error occurred.");
alert("Please enter correct Origin/Destination location");
parent.window.returnValue = "0";
window.close();
}
}
function onGDirectionsLoad() {
// Use this function to access information about the latest load()
// results.
// e.g.
// document.getElementById("getStatus").innerHTML = gdir.getStatus().code;
// and yada yada yada...
}
On Tue, Oct 4, 2011 at 10:28 AM, [email protected]
<[email protected]>wrote:
> On Oct 4, 7:08 am, Sim <[email protected]> wrote:
> > I am using google APIs to get maps and directions in my application.
> > How can i find if 2 addresses have more than 1 route?
> > e.g
> > Address 1 - 3111 s dixie Hwy FL
> > Address2 - 501 n olive ave west palm beach 33401.
> >
> > It returns me the correct map but the address it return is different
> > one.
>
> 3111 s dixie Hwy FL is not specific enough, I get four matches.
>
>
> http://www.geocodezip.com/example_geo2.asp?addr1=3111%20s%20dixie%20Hwy%20FL&addr2=501%20n%20olive%20ave%20west%20palm%20beach%2033401&geocode=1&geocode=2
>
>
> Start:
> Found 4 results
> [ 0 ]: 3111 S Dixie Hwy, Homestead, FL 33030, USA (25.4810245,
> -80.4632946)
> [ 1 ]: 3111 S Dixie Hwy, West Palm Beach, FL 33405, USA (26.685295,
> -80.055271)
> [ 2 ]: 3111 S Dixie Hwy, Delray Beach, FL 33483, USA (26.4265729,
> -80.0756844)
> [ 3 ]: 3111 S Dixie Hwy, Perry, FL 32348, USA (30.0840687,
> -83.5625118)
> End:
> Found 1 results
> [ 0 ]: 501 N Olive Ave, West Palm Beach, FL 33401, USA (26.7171897,
> -80.0520163)
>
> -- Larry
>
> --
> You received this message because you are subscribed to the Google Groups
> "Google Maps API V2" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/google-maps-api?hl=en.
>
>
--
You received this message because you are subscribed to the Google Groups
"Google Maps API V2" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-maps-api?hl=en.