Last active
September 4, 2020 15:49
-
-
Save ssbreno/6c98f1bca91d0d7361fb807abd6fa543 to your computer and use it in GitHub Desktop.
ShowLocationState
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$telefones['552141054905'] = ['localidade' => 'Rio de Janeiro', 'hrefTel' => '552141054905', 'telefone' => '(21) 4105-4905', 'uf' => 'RJ']; | |
$telefones['551920421507'] = ['localidade' => 'Campinas', 'hrefTel' => '551920421507', 'telefone' => '(19) 2042-1507', 'uf' => 'SP']; | |
$telefones['554135421977'] = ['localidade' => 'Curitiba', 'hrefTel' => '554135421977', 'telefone' => '(41) 3542-1977', 'uf' => 'PR']; | |
$telefones['556231420088'] = ['localidade' => 'Goiânia', 'hrefTel' => '556231420088', 'telefone' => '(62) 3142-0088', 'uf' => 'GO']; | |
$telefones['558331420749'] = ['localidade' => 'João Pessoa', 'hrefTel' => '558331420749', 'telefone' => '(83) 3142-0749', 'uf' => 'PB']; | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*** | |
* | |
* Variaveis Globais | |
* API - API para pegar pelo IP | |
* localidadesJson = caminho do .json | |
* storageEstado = Chave no localStorage | |
* | |
*/ | |
function Localidades(){ | |
this.localidadesJson = "./assets/js/localidades.json"; | |
this.API = 'https://ipapi.co/json'; | |
this.storageEstado = 'uf'; | |
this.getEstadoStorage = function(){ | |
return localStorage.getItem(this.storageEstado); | |
} | |
this.atualizaEstadoStorage = function(estado){ | |
localStorage.setItem(this.storageEstado, estado); | |
} | |
this.getEstadoFromAPIorStorage = function(callback) { | |
var estado = this.getEstadoStorage(); | |
if (typeof estado === 'string') { | |
callback(estado); | |
return; | |
} | |
var $this = this; | |
$.getJSON(this.API, function (response) { | |
var estado = response.region_code; | |
if (response.country_code !== 'BR') { | |
estado = 'RJ'; | |
} | |
$this.atualizaEstadoStorage(estado); | |
callback(estado); | |
}).fail(callback('RJ')); | |
} | |
this.getTelefoneProximo = function(callback){ | |
var $this = this; | |
this.getEstadoFromAPIorStorage(function(estado){ | |
if(!estado) estado = 'RJ'; | |
$.getJSON($this.localidadesJson, function(data){ | |
if(!data || data.length === 0) return; | |
// Busca por estado igual | |
var telefone = data.filter(function(localidade){ | |
return localidade.uf == estado; | |
}); | |
// Não achou nenhum igual, busca nas proximidades | |
if(telefone.length === 0){ | |
data.forEach(function(localidade){ | |
if(localidade.proximidade.indexOf(estado) !== -1){ | |
telefone = [localidade]; | |
} | |
}); | |
} | |
telefone = telefone[0]; | |
if(!telefone) { | |
callback(); | |
} | |
var telefoneLocal = telefone.telefone; | |
var telefoneHref = telefone.hrefTel; | |
callback({telefone: telefoneLocal, telefoneHref, uf:estado}); | |
}).fail(callback); | |
}); | |
} | |
this.preencheTelefones = function(){ | |
this.getTelefoneProximo(function(telefone){ | |
if(!telefone) return; | |
var telefoneLocal = telefone.telefone; | |
var telefoneHref = telefone.telefoneHref; | |
var $telefonePrincipal = $('.tel-principal'); | |
$telefonePrincipal.text(telefoneLocal); | |
if($telefonePrincipal.attr('href')) { | |
$telefonePrincipal.attr('href', 'tel:+'+ telefoneHref); | |
} | |
if($('.a-tel').attr('href')) { | |
$('.a-tel').attr('href', 'tel:+'+ telefoneHref); | |
} | |
$(".secundario_" + telefone.uf).hide(); | |
}) | |
} | |
} | |
new Localidades().preencheTelefones(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
include_once('array.php'); | |
?> | |
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8" /> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | |
<meta http-equiv="X-UA-Compatible" content="ie=edge" /> | |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> | |
<script type="text/javascript" src="getLocalidade.js"></script> | |
<title>Google Maps</title> | |
</head> | |
<body> | |
<div class="whatsapp-bar d-none d-lg-block" data-sticky-top='.whatsapp-start'> | |
<div class="container-fluid"> | |
<button type="button" name="Fechar" title="Fechar" class="close" data-dismiss=".whatsapp-bar"> | |
<span aria-hidden="true">×</span> | |
</button> | |
<div class="row"> | |
<div class="col-12 text-center"> | |
<h6 class='mb-3'>Ainda não conhece o shosp?</h6> | |
<a href="#" class="btn btn-warning btnModal" data-toggle="modal" data-target="#callMeModal"><span | |
class="callcenter"></span>Solicitar ligação</a> | |
<a class="btn btn-primary btn-phone tel-principal" href="tel:+<?= $telefones['552141054905']['hrefTel'] ?>" > | |
<span class="texto"> | |
<span class="ligue">Ligue pra nós</span> | |
<span class="tel tel-principal"><?= $telefones['552141054905']['telefone'] ?></span> | |
</span> | |
</a> | |
<a href='https://web.whatsapp.com/send?phone=556296819017' target="_blank" class="btn btn-whatsapp"><span | |
class="icon-whatsapp1 mr-3"></span>Fale no Whatsapp</a> | |
</div> | |
</div> | |
</div> | |
</div> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ | |
{ | |
"localidade": "Rio de Janeiro", | |
"hrefTel": "552141054905", | |
"telefone": "(21) 4105-4905", | |
"uf": "RJ", | |
"proximidade": [ | |
"ES" | |
] | |
}, | |
{ | |
"localidade": "Campinas", | |
"hrefTel": "551920421507", | |
"telefone": "(19) 2042-1507", | |
"uf": "SP", | |
"proximidade": [ | |
"MG" | |
] | |
}, | |
{ | |
"localidade": "Curitiba", | |
"hrefTel": "554135421977", | |
"telefone": "(41) 3542-1977", | |
"uf": "PR", | |
"proximidade": [ | |
"RS", | |
"SC" | |
] | |
}, | |
{ | |
"localidade": "Goiânia", | |
"hrefTel": "556231420088", | |
"telefone": "(62) 3142-0088", | |
"uf": "GO", | |
"proximidade": [ | |
"MT", | |
"MS", | |
"DF" | |
] | |
}, | |
{ | |
"localidade": "João Pessoa", | |
"hrefTel": "558331420749", | |
"telefone": "(83) 3142-0749", | |
"uf": "PB", | |
"proximidade": [ | |
"AL", | |
"BA", | |
"CE", | |
"MA", | |
"PE", | |
"PI", | |
"RN", | |
"SE", | |
"AC", | |
"AM", | |
"AP", | |
"PA", | |
"RO", | |
"RR", | |
"TO" | |
] | |
} | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment