Hi all,
I'm new to JavaScript and Google Maps API. I got some problems but I cannot find out the reason. Hope someone can help me.
What I tried to do:
I'm trying to develop an application in MFC (Visual Studio 2005) with a html dialog showing a Google map. I will send location data from the MFC application to a JS function to calculate directions. Another JS function will return the number of routes and steps in the GDirection object. The result will be sent back as a message string.
The problem I encountered:
If I open the html file using IE and manually input the location data and use alert function to show the message, everything works well. I can send the location data from MFC to JS. However, after that, I cannot get the route number back... It always returns the number as "undefined".
Some codes:
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);
}
}
function UpdateGPS(ar)
{
var a = new VBArray(ar);
var b = a.toArray();
rExp = /(\w|\s)*[^@]/ig;
var res = b[0].match(rExp);
lan = parseInt(res[1]) / 1000000;
lon = parseInt(res[2]) / 1000000;
str = lan + "," + lon;
setDirections(str, "1.300983,103.772704");
}
function getRoute()
{
return message;
}
function setDirections(fromAddress, toAddress)
{
gdir.load("from: " + fromAddress + " to: " + toAddress, {getPolyline:true, getSteps:true, travelMode:G_TRAVEL_MODE_WALKING});
}
function onGDirectionsLoad()
{
n_route = gdir.getNumRoutes();
message = str + ". we have " + n_route + " route.";
alert(message);
}
Can someone help me here? Thanks a lot!