Google 地图地理定位 API 用于 wifiAccessPoints returns 找不到地理定位

Google Maps Geolocation API for wifiAccessPoints returns geolocation not found

我正在使用 google API 使用 POST 方法

将 wifi 数据转换为位置数据

https://www.googleapis.com/geolocation/v1/geolocate?key=YOUR_API_KEY

    {

  "considerIp": "false",
 "wifiAccessPoints": [
  {
   "macAddress": "01:23:45:67:89:AB",
   "signalStrength": 8,
   "age": 0,
   "signalToNoiseRatio": -65,
   "channel": 8
  },
 {
   "signalStrength": 4,
   "age": 0
  }
 ]
}

我得到的响应是

{
  "error": {
  "errors": [
   {
    "domain": "geolocation",
    "reason": "notFound",
    "message": "Not Found"
  }
],
"code": 404,
"message": "Not Found"
}
}

这与我之前使用的代码相同,我在上个月的测试期间获得了纬度和经度。 突然我得到了这个失败的回应。 我们甚至尝试了 Mac 个我们之前测试过的地址,现在 return 个相同的响应。 在上面的示例中,我们使用了 google 示例中使用的 mac 地址。但我们也尝试了之前获取数据的方法。

404: Not found错误响应表示没有返回结果。但是,您的请求有效。

您应该假设在某些情况下,地理定位会失败,并且您应该构建一个异常处理组件,如果地理定位确实发生错误,该组件不会失败。即使由于错误或用户拒绝浏览器提供位置的权限而未正确获取当前位置,您的应用程序也应该继续运行。

要确认这是问题所在,请在您的请求中将 considerIp 设置为 false。如果响应是 404,您已确认无法对您的 wifiAccessPoints 和 cellTowers 对象进行地理定位。

https://developers.google.com/maps/documentation/geolocation/intro

The request body's wifiAccessPoints array must contain two or more WiFi access point objects. macAddress is required; all other fields are optional.

据我所知,您的第二个 wifi 接入点需要一个 mac 地址。