Block Maps External Query Api

Asked

Viewed 54 times

1

In this code below I perform a query at the address and it returns me some data so far everything ok. What I wanted to know is ?

  • If there’s a way, if a customer enters an address in the United States returns a message "Area Not Allowed"
  • wanted to limit consultations only in Brazil

      function CalculaDistancia() {
        $('#litResultado').html('Aguarde...');
        // Instancia o DistanceMatrixService.
        var service = new google.maps.DistanceMatrixService();
        // Executa o DistanceMatrixService.
        service.getDistanceMatrix({
            origins: [$("#txtOrigem").val()], // Origem
            destinations: [$("#txtDestino").val()], // Destino
            travelMode: google.maps.TravelMode.DRIVING, // Modo (DRIVING | WALKING | BICYCLING)
            unitSystem: google.maps.UnitSystem.METRIC // Sistema de medida (METRIC | IMPERIAL)
        }, callback); // Vai chamar o callback
      }

      // Tratar o retorno do DistanceMatrixService
      function callback(response, status) {
        // Verificar o status.
        if (status != google.maps.DistanceMatrixStatus.OK) { // Se o status não for "OK".
            $("#litResultado").html(status);
        } else { // Se o status for "OK".
            $("#litResultado").html(" "); // Remove o "aguarde".

            // Popula os campos.
            $("#txtOrigemResultado").val(response.originAddresses);
            $("#txtDestinoResultado").val(response.destinationAddresses);
            $("#txtDistancia").val(response.rows[0].elements[0].distance.text); // se text Km se value em Metros
            
            /////////////////////////////////////////////////////////////////////////////////////////////////
            var tempo = response.rows[0].elements[0].duration.text;
            tempo = tempo.replace("day", "dia").replace("hour", "hora").replace("min", "min");
            $("#txtTempo").val(tempo);
          }
  }   /////////////////////////////////////////////////////////////////////////////////////////////////

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.