我正在尝试创建一个利用 Google Places API 的 android 应用程序,但我希望它列出当前不支持的地点类型。我知道我可以通过应用程序添加地点,但这样做有问题。我不断收到以下错误:
错误 400:(错误请求)您的客户端发出了格式错误或非法的请求。
我已经搜索了所有关于向places api提交添加请求的工作示例,但我似乎找不到任何可以告诉我我做错了什么的东西。下面是我尝试过的代码,大部分情况下我在各个网站上找到了它,但似乎仍然无法让它工作:
private static final String PLACE_ADD_URL = "https://maps.googleapis.com/maps/api/place/add/json?";
public PlacesList addPlace() throws Exception {
try {
Log.v(LOG_KEY,"Adding Place...");
GenericUrl reqUrl = new GenericUrl(PLACE_ADD_URL);
reqUrl.put("key", API_KEY);
Log.v(LOG_KEY, "Adding Place...");
reqUrl.put("Host: maps.googleapis.com","{\"location\":{\"lat\":39.977112,\"lng\":-74.182799},\"accuracy\":50.0,\"name\":\"Artisan's Brewery & Italian Grill\",\"types\":[\"other\"],\"language\":\"en\":HTTP/1.1}");
Log.v(LOG_KEY, "Requested URL= " + reqUrl);
HttpRequestFactory httpRequestFactory = createRequestFactory(HTTP_TRANSPORT);
HttpRequest request = httpRequestFactory.buildGetRequest(reqUrl);
Log.v(LOG_KEY, request.execute().parseAsString());
PlacesList place = request.execute().parseAs(PlacesList.class);
Log.v(LOG_KEY, "STATUS = " + place.status);
Log.v(LOG_KEY, "Place Added is = " + place);
return place;
} catch (HttpResponseException e) {
Log.v(LOG_KEY, e.getMessage());
throw e;
}
catch (IOException e) {
// TODO: handle exception
throw e;
}
}