通过JSON向Google商家信息添加位置详细信息

时间:2013-01-28 15:55:29

标签: java android json google-places-api

我正在使用Google Places API向我的Android应用添加位置,当我搜索这些地方时,我收到了姓名,经度和经度,但我无法检索格式化的地址或格式化的电话号码。我想知道是否无法添加位置详细信息,如地址,电话号码,网站等,或者我做错了什么。这是我正在使用的HTTP帖子:

public JSONObject addPlace(double lat, double lng, String type, String name) throws Exception {
    try {
        Log.v(LOG_KEY, "Adding Place...");
         String vic = "5/48 Pirrama Road, Pyrmont";
         String formtd_address = "5/48 Pirrama Road, Pyrmont NSW, Australia";
         String formtd_phone_number = "(02) 9374 4000";
         String myUrl = "http://maps.google.com/maps/place?cid=10281119596374313554";
         String myWebsite = "http://www.google.com.au/";

        HttpPost post = new HttpPost(PLACE_ADD_URL);
        String postBody = 
                    "{"+
                          "\"location\": {" +
                            "\"lat\": " + lat + "," +
                            "\"lng\": " + lng +
                           "}," + 
                           "\"accuracy\":50.0," +
                           "\"name\": \"" + name + "\"," +
                           "\"types\": [\"" + type + "\"]," +
                           "\"vicinity\":\""+ PlaceAdd.vic +"\","+
                           "\"formatted_address\":\""+ PlaceAdd.formtd_address +"\","+
                           "\"formatted_phone_number\":\""+ PlaceAdd.formtd_phone_number +"\","+
                           "\"url\":\""+ PlaceAdd.myUrl +"\","+
                           "\"website\":\""+ PlaceAdd.myWebsite +"\","+  
                           "\"language\": \"en\" " +

                      "}"; 

        StringEntity se = new StringEntity(postBody,HTTP.UTF_8);
        post.setEntity(se);
        ResponseHandler<String> responseHandler=new BasicResponseHandler();
        String responseBody = new DefaultHttpClient().execute(post, responseHandler);
        JSONObject response = new JSONObject(responseBody);
        Log.v(LOG_KEY, "Requested URL= " + PLACE_ADD_URL); 

        return response;

    } catch (HttpResponseException e) {
        Log.v(LOG_KEY, e.getResponse().parseAsString());
        throw e;
    }

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

所以我想我有两个问题。您是否可以在将应用中的位置添加到Google Places API时添加地点详细信息,如果是,我的代码是否有问题?

谢谢!

1 个答案:

答案 0 :(得分:0)

根据documentation,地方信息报告仅支持locationaccuracynametypeslanguage参数1}}请求。如果您认为支持添加地点详细信息是有用的功能,请提交Places API - Feature Request