Hi i'm trying to get directions from adress a to b. Gdirections gets
the route quite well but will not center the map after that, i've read
everything on the documentation and everywhere but can't find a
solution. here is what i do:

when user writes the 2 adresses i call the function:

function getRoute(){
  initialize();
  setDirections(routefrom+', '+countryfrom, routeto+', '+countryto);
}

function initialize() {
  if (GBrowserIsCompatible()) {
    map = new GMap2(document.getElementById('map_canvas'),{mapTypes:
[G_NORMAL_MAP]});
    map.setCenter(new GLatLng(51.917168,19.138184),6);
    map.addControl(new GLargeMapControl());
    gdir = new GDirections(map);
    GEvent.addListener(gdir, "load", onGDirectionsLoad);
    GEvent.addListener(gdir, "error", handleErrors);
  }
}

function setDirections(fromAddress, toAddress) {
  gdir.load("from: " + fromAddress + " to: " + toAddress, {'locale':
'en_US'});
}

function onGDirectionsLoad(){

 //here when i call for the star point and endpoint coordinates it
shows fine

  // i know the gdir after loading should center the map but it
doesn't
  // i've tried this (beneath), it will only center the map but won't
change the zoom (i get a return value for zoom 10 values less of what
should be or 0 if zoom should be <10)

  if(gdir.getStatus().code == G_GEO_SUCCESS) {
    map.setCenter(gdir.getBounds().getCenter());
    map.setZoom(map.getBoundsZoomLevel(gdir.getBounds()));
    alert(map.getBoundsZoomLevel(gdir.getBounds()));
  }
}


of course map and gdir are declared before as globals at the begining
of the script....

the problem only occurs after the first recall of the directions, the
second time getRoute is called it works fine....

any sugestions??

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google Maps API" 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
-~----------~----~----~----~------~----~------~--~---

Reply via email to