Click here to Skip to main content
15,891,745 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:
JavaScript
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) // this is where MFC send the location data to JS
    {
      var a = new VBArray(ar);
      var b = a.toArray();
      rExp = /(\w|\s)*[^@]/ig;
      var res = b[0].match(rExp);	// Name @ size @ free_space
      lan = parseInt(res[1]) / 1000000;
      lon = parseInt(res[2]) / 1000000;	
      str = lan + "," + lon;		
      setDirections(str, "1.300983,103.772704");
    } 
	
    function getRoute() // this is where JS should send information back to MFC
    {
      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!
Posted
Updated 14-May-10 2:41am
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900