我想使用mac地址获取设备的经度和纬度,而不是它没有返回任何值。
我已经激活了我的 Google Geolocation API 并启用了计费。请帮忙。
<?php
$mac = "E4:D5:3D:E4:05:BF";
//encode the data in JSON
$wifiAccessPoints = array("macAddress"=>$mac);
$wifiAccessPoints = json_encode($wifiAccessPoints);
$API_key = "AIzaSyApOf.................";
$url = "https://www.googleapis.com/geolocation/v1/geolocate?key=$API_key";
$client = curl_init($url);
//send the request to resource
curl_setopt($client, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($client, CURLOPT_HEADER, false);
curl_setopt($client, CURLOPT_POSTFIELDS, $wifiAccessPoints);
curl_setopt($client, CURLOPT_RETURNTRANSFER,true);
curl_setopt($client, CURLOPT_HTTPHEADER,array("Content-type: application/json", "Content-Length".strlen($wifiAccessPoints)));
curl_setopt($client,CURLOPT_POST,true);
//get response from request.
$response = curl_exec($client);
//decode format response
//$result = json_decode($response);
$status = curl_getinfo($client, CURLINFO_HTTP_CODE);
echo $status."<br>";
echo $response."<br>";
?>