当前位置: 动力学知识库 > 问答 > 编程问答 >

java - Google Places API, Adding a place always returns INVALID_REQUEST

问题描述:

Here's the code:

googleMapsAPICall = "https://maps.googleapis.com/maps/api/place/add/json?sensor=true&key=MY_KEY_HERE";

HttpPost post = new HttpPost(googleMapsAPICall);

String postBody = "{\"location\":{\"lat\":-33.8669710,\"lng\":151.1958750},\"accuracy\":50.0,\"name\":\"testingjson\",\"types\":[\"other\"],\"language\":\"en\"}";

StringEntity se = new StringEntity(postBody,HTTP.UTF_8);

post.setEntity(se);

httpClient = new DefaultHttpClient();

response = httpClient.execute(post);

Can you see something wrong?

网友答案:

The are a number of factors which can affect the response. Following are issues that I came across while adding places to my project: 1. 'type' of place was not listed in types understood by google. Make sure that type added is given in supported types. 2. The required types are all included in the request placed. Also make sure that it is in the right format as expected. (Please check the request body section in 'place add' to ensure your request validity.) 3. The request sent is in the correct format and encoded with right content type.

Hope, this answer was useful.

Regards, Karan

分享给朋友:
您可能感兴趣的文章:
随机阅读: