google-maps-api-3 - 来自 Amazon EC2 的地理定位请求

标签 google-maps-api-3 google-api google-geocoding-api google-geolocation

我正在部署一个向 Google Maps Geolocation API 发出请求的应用程序。我的请求从我的工作站顺利通过。但是每次我从亚马逊云中的服务器运行它时,我都会收到 400 Bad Request 错误。

下面是我要测试的示例 curl 请求。使用中的 API 允许任何 IP。

curl -d "{'wifiAccessPoints':[{'macAddress':'c8:d7:19:16:3b:63'},{'macAddress':'c8:d7:19:16:3b:61'}]}" -H "Content-Type: application/json" -i "https://www.googleapis.com/geolocation/v1/geolocate?key=PUTYOURKEYHERE" -v

以下是错误结果的示例
* About to connect() to www.googleapis.com port 443 (#0)
*   Trying 173.194.76.95... connected
* Connected to www.googleapis.com (173.194.76.95) port 443 (#0)
* Initializing NSS with certpath: sql:/etc/pki/nssdb
*   CAfile: /etc/pki/tls/certs/ca-bundle.crt
  CApath: none
* SSL connection using SSL_RSA_WITH_RC4_128_SHA
* Server certificate:
*   subject: CN=*.googleapis.com,O=Google Inc,L=Mountain View,ST=California,C=US
*   start date: Jan 15 14:37:40 2014 GMT
*   expire date: May 15 00:00:00 2014 GMT
*   common name: *.googleapis.com
*   issuer: CN=Google Internet Authority G2,O=Google Inc,C=US
> POST /geolocation/v1/geolocate?key=AIzaSyDzcv8DIbbeGBaONSq2kXh7g9AZbgsiUC8 HTTP/1.1
> User-Agent: curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.14.3.0 zlib/1.2.3 libidn/1.18 libssh2/1.4.2
> Host: www.googleapis.com
> Accept: */*
> Content-Type: application/json
> Content-Length: 93
> 
< HTTP/1.1 400 Bad Request
HTTP/1.1 400 Bad Request
< Content-Type: application/json; charset=UTF-8
Content-Type: application/json; charset=UTF-8
< Date: Thu, 30 Jan 2014 10:56:18 GMT
Date: Thu, 30 Jan 2014 10:56:18 GMT
< Expires: Thu, 30 Jan 2014 10:56:18 GMT
Expires: Thu, 30 Jan 2014 10:56:18 GMT
< Cache-Control: private, max-age=0
Cache-Control: private, max-age=0
< X-Content-Type-Options: nosniff
X-Content-Type-Options: nosniff
< X-Frame-Options: SAMEORIGIN
X-Frame-Options: SAMEORIGIN
< X-XSS-Protection: 1; mode=block
X-XSS-Protection: 1; mode=block
< Server: GSE
Server: GSE
< Alternate-Protocol: 443:quic
Alternate-Protocol: 443:quic
< Transfer-Encoding: chunked
Transfer-Encoding: chunked

< 
{
 "error": {
  "errors": [
   {
    "domain": "geolocation",
    "reason": "invalidRequest",
    "message": "Bad Request"
   }
  ],
  "code": 400,
  "message": "Bad Request"
 }
}
* Connection #0 to host www.googleapis.com left intact
* Closing connection #0

最佳答案

我遇到了完全相同的问题,出于某种原因,我遇到了相同的问题 curl命令可以在 ubuntu 上运行,但不能在 amazon ami (centos) 上运行。
解决方案是添加 considerIp: false到请求正文,如下所示:

{
    "considerIp": false,
    "wifiAccessPoints": [
        ...
    ]
}

关于google-maps-api-3 - 来自 Amazon EC2 的地理定位请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21416732/

相关文章:

javascript - Google map API 反向地理编码 - 结果类型?

php - 将 Googlemap 纬度和经度作为 javascript 传递到 HTML 表单

javascript - 为什么 AngularJS 在谷歌地图中显示标记而不是路线?

javascript - 从 google places 返回多种类型 autocompleteService.getPlacePredictions

google-api - Google 的 File Insert v2 API 无法识别 MIME TYPE application/vnd.google-apps.document

google-sheets - 使用api在谷歌电子表格中特定列的末尾附加一个新单元格(行)

ios - viewDidLoad 在更新当前位置后重置 Google map View

javascript - 未捕获的类型错误 : Cannot read property 'latitude' of undefined

javascript - Google Places JS API weekday_text

php - Google geocode API 不返回某些位置的结果