var map = null;
var geocoder = null;
var themarker = null;
var thegdir = null;
function initialize() {
if (GBrowserIsCompatible()) {
map = new GMap2(document.getElementById("map_canvas"));
map.setCenter(new GLatLng(37.4419, -122.1419), 14);
geocoder = new GClientGeocoder();
}
}
function showAddress(address, company) {
if (GBrowserIsCompatible()) {
geocoder = new GClientGeocoder();
if (geocoder) {
geocoder.getLatLng(
address,
function(point) {
if (!point) {
alert(address + " not found");
} else {
map = new GMap2(document.getElementById("map_canvas"));
map.setCenter(point, 14);
var marker = new GMarker(point);
map.addOverlay(marker);
// The inactive version of the direction info
var html = company + '
Directions: To here<\/a> - From here<\/a>';
// add markers to the map
marker.openInfoWindowHtml(html);
map.addControl(new GLargeMapControl());
map.addControl(new GMapTypeControl());
// make the info box show up when the marker is clicked
GEvent.addListener(marker, "click", function() {
marker.openInfoWindowHtml(html);
});
// === create a GDirections Object ===
var gdir=new GDirections(map, document.getElementById("directions"));
// === Array for decoding the failure codes ===
var reasons=[];
reasons[G_GEO_SUCCESS] = "Success";
reasons[G_GEO_MISSING_ADDRESS] = "Missing Address: The address was either missing or had no value.";
reasons[G_GEO_UNKNOWN_ADDRESS] = "Unknown Address: No corresponding geographic location could be found for the specified address.";
reasons[G_GEO_UNAVAILABLE_ADDRESS]= "Unavailable Address: The geocode for the given address cannot be returned due to legal or contractual reasons.";
reasons[G_GEO_BAD_KEY] = "Bad Key: The API key is either invalid or does not match the domain for which it was given";
reasons[G_GEO_TOO_MANY_QUERIES] = "Too Many Queries: The daily geocoding quota for this site has been exceeded.";
reasons[G_GEO_SERVER_ERROR] = "Server error: The geocoding request could not be successfully processed.";
reasons[G_GEO_BAD_REQUEST] = "A directions request could not be successfully parsed.";
reasons[G_GEO_MISSING_QUERY] = "No query was specified in the input.";
reasons[G_GEO_UNKNOWN_DIRECTIONS] = "The GDirections object could not compute directions between the points.";
// === catch Directions errors ===
GEvent.addListener(gdir, "error", function() {
var code = gdir.getStatus().code;
var reason="Code "+code;
if (reasons[code]) {
reason = reasons[code]
}
alert("Failed to obtain directions, "+reason);
});
// add the marker and directions object to the global vars
thegdir = gdir;
themarker = marker;
}
}
);
} // if (geocoder)
} // if (GBrowserIsCompatible())
}
// ===== request the directions =====
function getDirections() {
// ==== Set up the walk and avoid highways options ====
var opts = {};
if (document.getElementById("walk").checked) {
opts.travelMode = G_TRAVEL_MODE_WALKING;
}
if (document.getElementById("highways").checked) {
opts.avoidHighways = true;
}
// ==== set the start and end locations ====
var saddr = document.getElementById("saddr").value
var daddr = document.getElementById("daddr").value
thegdir.load("from: "+saddr+" to: "+daddr, opts);
}
// functions that open the directions forms
function tohere() {
if (GBrowserIsCompatible()) {
geocoder = new GClientGeocoder();
if (geocoder) {
var address = "62980 Boyd Acres Road # D1, Bend, OR 97701, United States";
geocoder.getLatLng(address,
function(point) {
if (!point) {
alert(address + " not found");
} else {
var company = "RV Outfitters";
var to_html = company + '
Directions: To here<\/b> - From here<\/a>' +
'
Start address: