views:

276

answers:

1

Hi.

I've got a problem with calling a function that should draw a route on a map. For some reason it just returns null.

My code from maps.js (some of it)

var map = null;
var gdir = null;

function initialize() {
    if (GBrowserIsCompatible()) {
     map = new GMap2(document.getElementById("map"));
     map.setCenter(new GLatLng(55.869147, 11.228027), 6);
     map.enableDoubleClickZoom();
     //map.enableScrollWheelZoom();
     map.enableContinuousZoom();
     map.addControl(new GOverviewMapControl());
     map.setUIToDefault();

     gdir = new GDirections(map, document.getElementById("directions"));

     GEvent.addListener(gdir, "error", handleErrors);
     GEvent.addListener(gdir, "addoverlay", onGDirectionsAddOverlay);

     //setDirections("Harald Jensens vej 9 9000 Aalborg", "Hadsundvej 182 9000 Aalborg", "da_DK");
    }
}

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

The initialize() function is added on <body onload=""> and in the end of my document I fire:

<script type="text/javascript">
     var startaddress = $("#<%= txtStartAddress.ClientID %>").val();
     var startzip = $("#<%= txtStartZip.ClientID %>").val();
     var startcity = $("#<%= txtStartCity.ClientID %>").val();

     var destinationaddress = $("#<%= txtDestinationAddress.ClientID %>").val();
     var destinationzip = $("#<%= txtDestinationZip.ClientID %>").val();
     var destinationcity = $("#<%= txtDestinationCity.ClientID %>").val();

     setDirections(startaddress + " " + startzip + " " + startcity, destinationaddress + " " + destinationzip + " " + destinationcity, "da_DK");
    </script>

This is what the input is on the setDirections

setDirections("Myrdalstræde 117 9220 Aalborg Øst", "Stationsmestervej 172 9200 Aalborg SV", "da_DK")

But "gdir" is null? Can you see why? Thanks.

A: 

could you give a print off the setDirections ( under the javascript part ) ?

so with all the vars filled in.

thx

mhd
First post updated