forgive me, but I'm struggling with MVC a bit.
I have a function I've defined in my controller, to get the mileage between 2 cities from google.
I get loc1, and loc2 from a gridpanel, with a rowediting plugin.
I added an edit event to the rowediting plugin, which is where I get the editor.record.data values to pass to this function.
I'm trying to return the value back to the edit event function, and I can't seem to figure out how to do a callback with architect.
Code:
getgmapsdistance:function(loc1,loc2){
var geocoder, location1, location2, gDir;
geocoder = new GClientGeocoder();
gDir = new GDirections();
GEvent.addListener(gDir, "load", function() {
var drivingDistanceMiles = gDir.getDistance().meters / 1609.344;
var gmiles = drivingDistanceMiles;
//return gmiles;
});
var adr1=loc1 + ', AR, USA';
var adr2=loc2 + ', AR, USA';
geocoder.getLocations(adr1, function (response) {
if (!response || response.Status.code != 200)
{
console.log("Sorry, we were unable to geocode the first address");
}
else
{
location1 = {lat: response.Placemark[0].Point.coordinates[1], lon: response.Placemark[0].Point.coordinates[0], address: response.Placemark[0].address};
geocoder.getLocations(adr2, function (response) {
if (!response || response.Status.code != 200)
{
console.log("Sorry, we were unable to geocode the second address");
}
else
{
location2 = {lat: response.Placemark[0].Point.coordinates[1], lon: response.Placemark[0].Point.coordinates[0], address: response.Placemark[0].address};
gDir.load('from: ' + location1.address + ' to: ' + location2.address);
}
});
}
});
}
I'm sure it's simple, I just can't figure it out.
here's the way I'm calling the function:
Code:
onGridroweditingpluginEdit:function(editor,e,options){
MyApp.controller.MyControllers.prototype.getgmapsdistance(editor.record.data.Td_trfrom,editor.record.data.Td_trto);