I have the function below that calculates distances using a Google API.
I would like to know how to get the callback function returned.
<script type="text/javascript" src="_global/_js/jquery-2.1.4.min.js"></script>
<script src="http://maps.google.com/maps/api/js?sensor=false&key=my_key"></script><scripttype="text/javascript">
function CalculaDistancia(origem, destino) {
var service = new google.maps.DistanceMatrixService();
service.getDistanceMatrix( {
origins: [origem],
destinations: [destino],
travelMode: google.maps.TravelMode.DRIVING
}, callback);
return callback;
}
function callback(response, status) {
if (status == google.maps.DistanceMatrixStatus.OK) {
distancia = response.rows[0].elements[0].distance.value;
km = distancia/1000;
kmr = Math.ceil(km/100);
frete = kmr * 100;
alert (frete);
}
}
</script>
<a href="javascript:CalculaDistancia('36880000', '28890185');">calcular</a>
As it is, alert(frete)
normally alerts.
But I can not retrieve this value from within the CalculaDistancia()
function.