【问题标题】:Adding you own place using Google places API in android在 android 中使用 Google Places API 添加您自己的地点
【发布时间】:2012-03-12 16:52:35
【问题描述】:

我想在 android 中使用 Google Places API 添加我自己的地方我正在使用以下代码 sn-p,但是它给了我这个例外:

com.google.api.client.http.HttpResponseException: 400 错误请求

我的代码 sn-p 是:

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);
        reqUrl.put("sensor", "false");
        Log.v(LOG_KEY, "Adding Place...");
        //reqUrl.put("Host:", "maps.googleapis.com");
        reqUrl.put("Host: maps.googleapis.com","{\"location\":{\"lat\":-33.8733721,\"lng\":151.2012871},\"accuracy\":50.0,\"name\":\"harbour\",\"types\":[\"food\"],\"language\":\"en\"}");
        Log.v(LOG_KEY, "Requested URL= " + reqUrl);

        HttpRequestFactory httpRequestFactory = createRequestFactory(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.getResponse().parseAsString());
        throw e;
    }

    catch (IOException e) {
        // TODO: handle exception
        throw e;
    }
}  

现在我玩了很多这个异常但无法解决,我应该如何传递这个请求 URL?我的做法是对还是错??

【问题讨论】:

标签: android google-maps google-api-java-client google-places-api


【解决方案1】:

我将 Key 返回为 null。现在我通过了正确的密钥,它工作正常

【讨论】:

  • 呵呵,我的 ID @NaeemShah 是什么意思?电子邮件?只是发布堆栈溢出。我唯一的问题是在搜索中看不到添加的位置,并且 url 不在详细响应中。见这里stackoverflow.com/questions/8444880/…
  • 您好,我使用相同的代码并遇到相同的问题,请提供另一种方法。
  • 当您执行搜索时,您能否过滤并只获取您自己的地点?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-07-09
  • 1970-01-01
  • 2012-12-23
  • 1970-01-01
  • 2015-09-19
  • 1970-01-01
相关资源
最近更新 更多