Geolocation 返回空结果的地理位置代码

Geolocation 返回空结果的地理位置代码,geolocation,mac-address,google-geolocation,Geolocation,Mac Address,Google Geolocation,我想使用mac地址获取设备经度和纬度,而不是它不返回任何值 我已激活我的谷歌地理定位API,并已启用计费。请帮忙 <?php $mac = "E4:D5:3D:E4:05:BF"; //encode the data in JSON $wifiAccessPoints = array("macAddress"=>$mac); $wifiAccessPoints = json_encode($wifiAcce

我想使用mac地址获取设备经度和纬度,而不是它不返回任何值

我已激活我的谷歌地理定位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>";

        ?>     

返回的错误表明您的请求格式正确,但API找不到它的地理位置。对于您的结果,专家有以下说法:

原因:未找到
域:地理定位
状态代码:404
描述:请求有效,但未返回任何结果。

因此,看起来您成功地执行了请求,但谷歌并不总是能够告诉您特定WiFi接入点的位置(不可能期望他们都知道)

文件还指出

请求主体的wifiAccessPoints数组必须包含两个或多个WiFi接入点对象。macAddress是必需的;所有其他字段都是可选的


看起来您只有一个访问点,通过IP进行查找可能更准确。有大量关于如何重新格式化输入JSON的信息。

欢迎使用SO。您是否收到任何错误消息?
echo
ing
$status
$response
的结果是什么?$status返回0$response为空,我没有收到任何错误消息尝试使用Fiddler或WireShark等工具查看API返回的原始HTTP响应,这将使您更好地了解正在发生的情况。这是我得到的错误:
{“error”:{“errors”:[{“domain”:“geolocation”,“reason”:“notFound”,“message”:“notFound”}],“code”:404,“message”:“notFound”}