基于Cell ID和LAC的地理定位

时间:2015-01-30 07:05:25

标签: google-maps geolocation cellid

我有以下代码:

<HTML>
<?php

include('Net/SSH2.php');


$ssh = new Net_SSH2('my ip');
if (!$ssh->login('user', 'pass')){
		exit('Login Failed');
		}
$msisdn = $_POST['msisdn'];

$result = $ssh->exec('/usr/src/artsx/ash1.sh  '.$msisdn.'');



//echo $result; 
echo "<br>";

$array = explode(' ',$result);

//print_r($array);


$mcc = $array[0];
$mnc = $array[1];
$lac = $array[2];
$cell = $array[3];

//echo $mcc;
//echo $mnc;
//echo $lac;
//echo $cell;




$data = array(
"homeMobileCountryCode" => $mcc,
"homeMobileNetworkCode" => $mnc,
"radioType" => "gsm",
"cellTowers" => array( array(  
   "cellId" => $cell,
   "locationAreaCode" => $lac,
   "mobileCountryCode" => $mcc,
   "mobileNetworkCode" => $mnc
))
);


$url = "http://www.googleapis.com/geolocation/v1/geolocate?key=my_key";

function curl_get_contents($url)
{
	$ch = curl_init($url);
	curl_setopt($ch,CURLOPT_RETURNTRANSFER, 1);
	curl_setopt($ch,CURLOPT_FOLLOWLOCATION, 1);
	curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, 0);
	curl_setopt($ch,CURLOPT_SSL_VERIFYHOST, 0);
	$data = curl_exec($ch);
	curl_close($ch);
	return $data;
} 

print_r($data); 

$json = json_decode(curl_get_contents($url));

$options = array(
    	  'http' => array(
        'header'  => "Content-Type: application/json\r\n",
        'method'  => 'POST',
        'content' => json_encode($data),
    ),
);
print_r($json);


$context  = stream_context_create($options);
$result = file_get_contents($url, false, $context);
$result = json_decode($result,true);

echo $result;

$location=$result['location'];
$lat=$location['lat'];
$lng=$location['lng'];

//echo $lat;
echo "$lat $lng\n";

?>

我收到的回复是:

  

警告:file_get_contents(http://www.googleapis.com/geolocation/v1/geolocate?key=my_key):无法打开流:HTTP请求失败! HTTP / 1.1 401在第81行的D:\ Apache24 \ htdocs \ lookup \ glookup.php中未经授权。

任何想法可能是什么原因? 我已经检查过allow_url_fopen,并将其设置为“On”。

0 个答案:

没有答案