directman

<<< Back

получение адреса по GPS координатам

получение адреса по GPS координатам (длинный вариант)

$zap=$params['zapros'];
//echo $zap; 
$x=$zap[0];
$y=$zap[1];

if ($x==""){$x=gg('38614954354422955857342.lat');}
if ($y==""){$y=gg('38614954354422955857342.lng');}

echo "x:".$x.";y=".$y;

$url='http://maps.googleapis.com/maps/api/geocode/xml?latlng='.$x.',' .$y.'&sensor=false&language=ru'; 
//echo $url;
//в обратную сторону 
//url_request = "http://maps.googleapis.com/maps/api/geocode/xml?sensor=false&address=" + RussianStringToURLEncode(city) + " " + RussianStringToURLEncode(street)

  $fields = array(
    'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
    'Accept-Charset: windows-1251,utf-8;q=0.7,*;q=0.3',
    'Accept-Language: ru-RU,ru;q=0.8,en-US;q=0.6,en;q=0.4',
    'Connection: keep-alive',
    'User-Agent: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.76 Safari/537.36'
     );

foreach($fields as $key=>$value)
{ $fields_string .= $key.'='.urlencode($value).'&'; }
//echo $fields_string;
//echo '\n';
rtrim($fields_string, '&');

   $ch = curl_init();   
   curl_setopt($ch, CURLOPT_URL, $url);
   curl_setopt($ch, CURLOPT_POST, count($fields));   
   curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
   curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
   curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
   curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
   curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); 
   $result = curl_exec($ch);
//echo $result;
   curl_close($ch);

//echo $result;
$xml = simplexml_load_string($result);
//echo $xml ;
//$otvet=$xml->GeocodeResponce->result->formatted_address; 
//$otvet=$xml->GeocodeResponse->result->formatted_address; 
$otvet=$xml->result->formatted_address; 
//$otvet=$xml; 
echo $otvet;
return $otvet; 

Короткий вариант

extract( $params );
$URL = "http://maps.googleapis.com/maps/api/geocode/json?latlng=${lat},${lng}&sensor=false&language=ru";
$data = getUrl( $URL );
$json = json_decode( $data );
$addr = $json->results[0]->formatted_address;
return $addr;

Discuss (2) (1)

Екатеринбург, Россия

На форуме: directman66