Advertisement
Guest User

Untitled

a guest
Aug 19th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.         /**
  2.          * buscaLatLongEndereco
  3.          *
  4.          * busca a latitude e longitude dado um endereço
  5.          *
  6.          * @access public
  7.          * @author Lucas Renato
  8.          * @since  11/2015
  9.          * @param  Object
  10.          * @return void
  11.          *
  12.          */
  13.         this.buscaLatLongEndereco = function(Pdv){
  14.  
  15.             var q = $q.defer();
  16.  
  17.             // seta a string de endereço
  18.             var endereco = Pdv.logradouro + ' ' + Pdv.endereco + ', ' + Pdv.numero
  19.              + ', ' + Pdv.bairro + ' - ' + Pdv.cidade + ' - ' + Pdv.estado;
  20.  
  21.             // cria um novo geocoder
  22.             var geocoder = new google.maps.Geocoder();
  23.            
  24.             // seta LatLong
  25.             var LatLong = [];
  26.  
  27.             // chama a função geocoder passando endereço
  28.             geocoder.geocode( { 'address': endereco}, function(results, status) {
  29.  
  30.                 // verifica se conseguiu buscar o endereço
  31.                 if (status == google.maps.GeocoderStatus.OK) {
  32.  
  33.                     // seta latitude e longitude
  34.                     LatLong[0] = results[0].geometry.location.lat();
  35.                     LatLong[1] = results[0].geometry.location.lng();
  36.  
  37.                     // seta promessa como sucesso
  38.                     q.resolve(LatLong);
  39.                 } else {
  40.  
  41.                     // seta promessa como falha
  42.                     q.reject();
  43.                 }
  44.             });
  45.  
  46.             //retorna a promessa
  47.             return q.promise;
  48.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement