Google map ile rota çizdirme konusunda bazı çalışmalarım var. Su anda iki belirli nokta arasında(amerikadaki şehirler,buyuk bilindik yerler) harita uzerinde yollarda rota çizebiliyorum. fakat benim yapmak istedigim A noktasına B ve C noktalarından ayrı ayrı rota çizdirmek. Umarım anlatabilmisimdir mesela Los Angeles'e Anaheim ve Long Beach dan rotayı aynı anda çizdirmek istiyorum... Kodum assagıda inceleyebilirsiniz eger yardım edebilirseniz cok sevinirim.
var map; var gdir; var geocoder = null; var addressMarker;
//Mouse in out (Shows controls when mouse is on map, Hides when out of map.) GMap2.prototype.hoverControls = function(opt_noCloseIw){ var theMap = this; theMap.hideControls(); GEvent.addListener(theMap, "mouseover", function(){ theMap.showControls(); }); GEvent.addListener(theMap, "mouseout", function(){ theMap.hideControls(); });
function initialize() { if (GBrowserIsCompatible()) { map = new GMap2(document.getElementById("map_canvas")); gdir = new GDirections(map, document.getElementById("directions")); GEvent.addListener(gdir, "load", onGDirectionsLoad); GEvent.addListener(gdir, "error", handleErrors); //map controls Zoom map.addControl(new GLargeMapControl()); //sets center to given location map.setCenter(new GLatLng(33.9068,-118.1909), 10); //Adds controls to select Map Type map.addControl(new GMapTypeControl()); map.hoverControls(); //Coordinates GEvent.addListener(map, "mousemove", function(point){document.getElementById("mouse").value=point.toUrlValue();}); } } //route function setDirections(fromAddress, toAddress, locale) { gdir.load("from: " + fromAddress + " to: " + toAddress, { "locale": locale }); }
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_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);