【发布时间】:2014-11-06 13:08:23
【问题描述】:
我正在创建一个 android 应用程序,用于通过使用 google places api 搜索在附近的 google map 上添加和删除地点。我可以从我的应用程序中添加新地点,这些地点显示在附近的搜索结果中。现在当我尝试删除任何使用地点删除操作的地点,它总是给出 INVALID_REQUEST 响应。
这是我删除地点的网址:
String url="https://maps.googleapis.com/maps/api/place/delete/json?key=MY BROWSER KEY";
new delete().execute(url);
我删除地点的代码是:
public class delete extends AsyncTask<String, Void, String>{
@Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(UserBuisness.this);
pDialog.setMessage("deleting..");
pDialog.setIndeterminate(false);
pDialog.setCancelable(true);
pDialog.show();
}
@Override
protected String doInBackground(String... url) {
// TODO Auto-generated method stub
StringBuilder placesRemover = new StringBuilder();
for (String placeDeleteURL : url) {
HttpClient httpclientdelete = new DefaultHttpClient();
HttpPost httpPostDelete = new HttpPost(placeDeleteURL);
InputStream inputStream = null;
try {
JSONObject json=new JSONObject();
try {
//place_id contains place_id of place to be deleted
json.put("placeid",place_id);
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String postBodyDelete=json.toString();
StringEntity se = new StringEntity(postBodyDelete,HTTP.UTF_8);
httpPostDelete.setEntity(se);
HttpResponse httpResponse = httpclientdelete.execute(httpPostDelete);
inputStream = httpResponse.getEntity().getContent();
if(inputStream != null){
InputStreamReader placesInputDelete = new InputStreamReader(inputStream);
//use buffered reader to process
BufferedReader placesRemoverReader = new BufferedReader(placesInputDelete);
//read a line at a time, append to string builder
String lineIn;
while ((lineIn = placesRemoverReader.readLine()) != null) {
placesRemover.append(lineIn);
}
}
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return placesRemover.toString();
}
protected void onPostExecute(String result) {
JSONObject response=null;
String sam="";
try {
response=new JSONObject(result);
sam=response.getString("status");
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
pDialog.dismiss();
Toast.makeText(getApplicationContext(), sam, 1000).show();
}
}
我没有得到 INVALID_REQUEST 的原因,因为 URL 和帖子正文的格式与 google 地方操作删除地点所要求的格式相同。感谢任何形式的帮助。
【问题讨论】: