【问题标题】:google place action delete places gives invalid request谷歌地点操作删除地点给出无效请求
【发布时间】: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 地方操作删除地点所要求的格式相同。感谢任何形式的帮助。

【问题讨论】:

    标签: android google-places-api


    【解决方案1】:

    我刚刚遇到了同样的问题,并发现这是 Google 文档中的一个错误。 deleting a place 的文档清楚地说明(在两个地方)地点 id 的 JSON 键是“placeid”。

    POST https://maps.googleapis.com/maps/api/place/delete/json?key=AddYourOwnKeyHere HTTP/1.1
    Host: maps.googleapis.com
    
    {
      "placeid": "place ID"
    }
    
    ...
    
    placeid: A string identifying the place that must be deleted, returned from a place search.
    

    虽然正确的键实际上是“place_id”,这与其他 API 调用是一致的。

    因此,在您的情况下,您只需要更新这一行:

    json.put("placeid",place_id);
    

    变成这样:

    json.put("place_id",place_id);
    

    我知道这是一个迟到的答案,但我希望这仍然有帮助!我还向 Google 企业支持部门开了一张票,以确保文档中的这个错误得到解决。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-06-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-11
      • 2014-11-18
      相关资源
      最近更新 更多