Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parse error on Google GeoLocate API sample JSON

Has Google changed their GeoLocation api and not updated the documentation?

I have been following their example code verbatim off of the following page

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

I pasted the sample request into a file on my system called ex.json. I double checked that my Google Maps Geolocation API is set to on and executed the following curl command

curl -d ex.json -H "Content-Type: application/json" -i "https://www.googleapis.com/geolocation/v1/geolocate?key=[My key, yes I pasted my actual key in]"

I received the following response

{
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "parseError",
    "message": "Parse Error"
   }
  ],
  "code": 400,
  "message": "Parse Error"
 }
}

Which according to the documentation means that there is something wrong with the example json they provided. Just for completeness the sample json looks like

{
 "homeMobileCountryCode": 310,
 "homeMobileNetworkCode": 260,
 "radioType": "gsm",
 "carrier": "T-Mobile",
 "cellTowers": [
  {
   "cellId": 39627456,
   "locationAreaCode": 40495,
   "mobileCountryCode": 310,
   "mobileNetworkCode": 260,
   "age": 0,
   "signalStrength": -95
  }
 ],
 "wifiAccessPoints": [
  {
   "macAddress": "01:23:45:67:89:AB",
   "signalStrength": 8,
   "age": 0,
   "signalToNoiseRatio": -65,
   "channel": 8
  },
  {
   "macAddress": "01:23:45:67:89:AC",
   "signalStrength": 4,
   "age": 0
  }
 ]
}

JsonLint verified that it is proper Json, and the documentation says that all fields are optional. What am I missing, was some required field added after the documentation was written?

like image 328
JME Avatar asked Jul 03 '26 09:07

JME


1 Answers

Curl needs "-X POST" as extra parameter. Works like this:

curl 'https://www.googleapis.com/geolocation/v1/geolocate?key=YOURKEY' -X POST -H "Content-Type: application/json" -d @yourjsonfile.json
like image 188
user159211 Avatar answered Jul 05 '26 22:07

user159211



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!