其他分享
首页 > 其他分享> > 如何在android中使用Google Place Check-Ins

如何在android中使用Google Place Check-Ins

作者:互联网

我使用Google Places API检索特定位置内和周围的地点.通过解析xml文件,我获得了所需的位置及其详细信息.我需要到特定的地方办理登机手续.我不知道如何通过Http POST方法请求.这是我必须提出的要求.
place _reference – 我从地方请求获得的引用.
api_key – 我的api密钥.

POST https://maps.googleapis.com/maps/api/place/check-in/xml?sensor=true_or_false&key=api_keyHTTP/1.1
Host: maps.googleapis.com

<CheckInRequest>
  <reference>place_reference</reference>
</CheckInRequest>

我使用了以下代码:

try {
        String myXML = "<? xml version=1.0><CheckInRequest><reference>place_refrence</reference></CheckInRequest>";
            HttpClient httpClient = new DefaultHttpClient();
            HttpContext localContext = new BasicHttpContext();
            HttpPost httpPost = new HttpPost("https://maps.googleapis.com/maps/api/place/check-in/xml?sensor=true_or_false&key=api_key HTTP/1.1");

            List<NameValuePair> dataToPost = new ArrayList<NameValuePair>();

            dataToPost.add(new BasicNameValuePair("yourxml", myXML));

            httpPost.setEntity(new UrlEncodedFormEntity(dataToPost));

            HttpResponse response = httpClient.execute(httpPost, localContext);
            Log.v("Check in Response", "" + response);
        } catch (Exception e) {
            e.printStackTrace();
        }

但是在运行此代码时我遇到了这个异常.

 12-19 18:18:58.153: V/Util response(455): <!DOCTYPE html>
12-19 18:18:58.153: V/Util response(455): <html lang=en>
12-19 18:18:58.153: V/Util response(455):   <meta charset=utf-8>
12-19 18:18:58.153: V/Util response(455):   <title>Error 400 (Bad Request)!!1</title>
12-19 18:18:58.153: V/Util response(455):   <style>
12-19 18:18:58.153: V/Util response(455):     *{margin:0;padding:0}html,code{font:15px/22px arial,sans-serif}html{background:#fff;color:#222;padding:15px}body{background:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAKsAAADVCAMAAAAfHvCaAAAAGFBMVEVYn%2BH%2F%2F%2F%2Bex%2B3U5vd7s%2Bfq8%2Fs0itq72PMLUPvtAAASvklEQVR4AbXBC0JqCQxEwT5Jd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%2BsA21OumwuSQUJX1ZjLsVabqR6t7tUlrThhnjEC%2FFy6AKbCy45zdftmEutKm5UcSgHspY7XBEPVAFVHLoCUXPFkr3hi2wutba44QDr5iyeqQ3%2FiAccqOLQDhAV17pG0jZfUuZS5OJaGYiWF%2B2ypOV%2F4q5UQZtDu4G2xK10aeTlC1bhUslciQpYh7PSQtau8ErcVYZ4gXYDcUXLe1lrvBU%2B0VoutFRcWQWo4qwdTlYSr8Q9caDMwc3BDgl3xZpRb%2FORnuVCJHNlla2oOYmLQ8q7Ll6Ie6pgDaQKSCl8IF3WqAgPrbgU2VxpV1kje2EdoOWGlsOJuKMd1g14OdjNp1YjNY%2B0m0s15kYgJVlaFxBVOETuAOK9eEELrDmUli%2Fo8oy94S4Xl2LzQGuk

解决方法:

这个项目对您有所帮助:
http://code.google.com/p/android-protips-location/

搜索此文件:
http://code.google.com/p/android-protips-location/source/browse/trunk/src/com/radioactiveyak/location_best_practices/services/PlaceCheckinService.java

标签:android,http-post,http-status-code-400
来源: https://codeday.me/bug/20190630/1335949.html