繁体   English   中英

在Android中使用Google Places API添加自己的位置

[英]Adding you own place using Google places API in android

我想在Android中使用Google Places API添加自己的位置,我正在使用以下代码段,但是它给了我这个例外:

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

我的代码段是:

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? 我的方法是对还是错?

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM