Using The Google Maps Geolocation API
It looks like the problem is here is that the HttpPost object defaults to sending its parameters as x-www-form-urlencoded
, but you need to send it as application/json
. This thread explains what happens if you do this: How to use parameters with HttpPost
There are a couple of ways that should fix it. One is to set the Content-type header on the HttpPost object:
request.setHeader("Content-type", "application/json");
The other, which I think is better, is to use the setContentType method of StringEntity documented here
entity.setContentType("application/json");
Either of these single lines used before you send the request should fix the problem.
Is your JSON request object complete? I mean it looks like the keys you are using are part of a single "tower" description, but that this is just part of the larger request body, which should be formatted like:
{ "homeMobileCountryCode": 310, "homeMobileNetworkCode": 410, "radioType": "gsm", "carrier": "Vodafone", "cellTowers": [ // See the Cell Tower Objects section below. ], "wifiAccessPoints": [ // See the WiFi Access Point Objects section below. ]}
Where the tower objects are formatted like:
{'cellTowers': [ { 'cellId': 42, 'locationAreaCode': 415, 'mobileCountryCode': 310, 'mobileNetworkCode': 410, 'age': 0, 'signalStrength': -60, 'timingAdvance': 15 }]}
I guess I'm missing how your json object gets turned into the complete one?
https://developers.google.com/maps/documentation/business/geolocation/