Last active
February 7, 2019 00:24
-
-
Save guibranco/61fd9e1edfe960e4cc0ba670d33196ea to your computer and use it in GitHub Desktop.
Obtém latitude e longitude do site latlong.net via cURL (PHP) - Facebook - PHP Brasil - https://www.facebook.com/groups/142151625841770/permalink/2151325014924411/
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 | |
//Altere somente a variável abaixo: | |
$endereco = "Avenida Paulista, 1000 São Paulo SP BR"; | |
//Não altere nada daqui caso não saiba o que cada coisa faz! | |
$curl = curl_init(); | |
curl_setopt_array($curl, array( | |
CURLOPT_URL => "https://www.latlong.net/_spm4.php", | |
CURLOPT_RETURNTRANSFER => true, | |
CURLOPT_ENCODING => "", | |
CURLOPT_MAXREDIRS => 10, | |
CURLOPT_TIMEOUT => 30, | |
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, | |
CURLOPT_CUSTOMREQUEST => "POST", | |
CURLOPT_POSTFIELDS => "c1=".urlencode($endereco)."&action=gpcm&cp=", | |
CURLOPT_HTTPHEADER => array( | |
"Content-Type: application/x-www-form-urlencoded", | |
"x-requested-with: XMLHttpRequest" | |
), | |
)); | |
$response = curl_exec($curl); | |
$err = curl_error($curl); | |
curl_close($curl); | |
if($err) | |
die($err); | |
list($lat, $lon) = explode(",", $response); | |
//exibe a latitude e a longitude na página: | |
echo "Latitude: " . $lat; | |
echo "<br/>"; | |
echo "Longitude: " . $lon; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment