Created
December 4, 2012 12:08
-
-
Save deivisonarthur/4203156 to your computer and use it in GitHub Desktop.
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 | |
echo "<h1>Pega o sua latitude e longitude pelo seu IP em whatismyipaddress</h1>"; | |
$ip=$_SERVER['REMOTE_ADDR']; | |
$url=file_get_contents("http://whatismyipaddress.com/ip/$ip"); | |
preg_match_all('/<th>(.*?)<\/th><td>(.*?)<\/td>/s',$url,$output,PREG_SET_ORDER); | |
$pais=$output[9][2]; | |
$city=$output[11][2]; | |
$state=$output[10][2]; | |
$lat1=$output[12][2]; | |
$lon1=$output[13][2]; | |
echo $pais."<br />"; | |
echo $city."<br />"; | |
echo $state."<br />"; | |
echo $lat1."<br />"; | |
echo $lon1."<br />"; | |
echo "<br /><br />"; | |
echo "<h1>Pega o sua latitude e longitude pelo endereco em Google Maps</h1>"; | |
echo "<br /><label>Exe: trav yucatan 235, bonsucesso rio de janeiro</label><br />"; | |
function geolocal($endereco,$sensor=false){ | |
$sensor = ($sensor) ? 'true' : 'false'; | |
$endereco = utf8_encode(str_replace(" ", "+", $endereco)); | |
$url = 'http://maps.googleapis.com/maps/api/geocode/xml?address='.$endereco.'&sensor='.$sensor; | |
$xml = simplexml_load_file($url); | |
$latitude = $xml->result->geometry->location->lat; | |
$longitude = $xml->result->geometry->location->lng; | |
$cep = $xml->result->address_component[6]->long_name; | |
$pais = $xml->result->address_component[5]->long_name; | |
return array('lat' => $latitude, 'lon' => $longitude, 'cep' => $cep, 'pais' => $pais); | |
} | |
// COMO USAR A FUNÇÃO ============================================ | |
// número logradouro, cidade, uf | |
if( isset($_GET['end']) ){ | |
$end = $_GET['end']; | |
}else{ | |
$end = "trav yucatan 235, bonsucesso rio de janeiro"; | |
} | |
$endados = geolocal($end); | |
echo $endados['lat']."<br>"; | |
echo $endados['lon']."<br>"; | |
echo $endados['cep']."<br>"; | |
echo $endados['pais']."<br>"; | |
echo "<br /><br />"; | |
echo "<h1>Distancia entre os 2 pontos:</h1>"; | |
echo "<br /><label>Ou seja, entre seu endereco real(PC que vc esta comprando) e endereco informado em sua compra do Magento</label><br /><br />"; | |
$distance = (3958*3.1415926*sqrt(($endados['lat']-$lat1)*($endados['lat']-$lat1) + cos($endados['lat']/57.29578)*cos($lat1/57.29578)*($endados['lon']-$lon1)*($endados['lon']-$lon1))/180); | |
echo "<h1>".intval($distance)." km</h1>"; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment