1
I have the function below that calculates distances using a Google API.
I would like to know how to have the return of the function of callback.
<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>
<script type="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 stands, the alert(frete)
normally alert.
But I can’t recover that value from inside the function CalculaDistancia()
.
Google Maps API Warning: Sensornotrequired https://developers.google.com/maps/documentation/javascript/error-messages#sensor-not-required
– Carlos Rocha
just like that
– Carlos Rocha
Carlos, have you ever tried any of the solutions? Is there anything left to add to any of them?
– stderr