如何使用Google Places API for Android获得opening_hours [英] How to get opening_hours using the Google Places API for Android

查看:93
本文介绍了如何使用Google Places API for Android获得opening_hours的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Google Places API for Android ,我想要有权访问开放时间信息。我已经在 Google Places API网络服务中搜索<$ c属性$ c> opening_hours 是可以使用的,但在文档中您可以阅读:


Google Places API Web服务应该用在服务器应用程序中。如果您正在构建客户端应用,请查看Google地图JavaScript API中的Google Places API和Google地图库API中的网站库。

以下是对象地点 - 来自Google Apis for Android。
此处结果的详细信息 - 来自Places Api WS



如何使用api为Android获取某个地点的开放时间?那可能吗?我可以使用API​​的WS甚至谷歌说什么?
$ b

谢谢

  //这是一个以JSON格式解析Google Place信息的类
private class ParserTask extends AsyncTask< String,Integer,HashMap< String,String>> {

JSONObject jObject;
@Override
保护HashMap< String,String> doInBackground(String ... jsonData){

HashMap< String,String> hPlaceDetails = null;
PlaceDetailsJSONParser placeDetailsJsonParser = new PlaceDetailsJSONParser();

try {
//这个对象给出JSON
jObject = new JSONObject(jsonData [0]);

//此对象给出结果
JSONObject jresult = new JSONObject(jObject [1]);

//这个对象给了opening_hours
JSONObject jopening_hours = new JSONObject(jresult [2]);

//这个对象给出句点
JSONObject jperiods = new JSONObject(jopening_hours [2]);


$ b} catch(Exception e){
Log.d(Exception,e.toString());
}
返回jperiods;


//完成doInBackground()方法执行后执行
@Override
保护void onPostExecute(JsonObject句点){
HashMap< String ,字符串>期;

//把你的条件
换成(..)
{
JsonObject day = new JSONObject(periods [i]);
periods.put(key,day.get(day));

$ b}
}



JSON看起来像
https://maps.googleapis.com/maps/api/place/details/json placeid = ChIJKfCbbyyNWTkRAPM1frrO_sM& amp ; key = YOUR_API_KEY



美化json文件: http://jsonviewer.stack.hu/


I'm working with the Google Places API for Android and I want to have access to the opening hours information. I have searched and in the Google Places API Web Service the atribute opening_hours is abailable, but in the documentation you can read:

The Google Places API Web Service should be used in server applications. If you're building a client-side app, check out the Google Places API for Android and Site Library in Google Maps JavaScript API.

Here is object Place - from Google Apis for Android. And here the result of the details of one place - from Places Api W.S.

How can I get the opening hours of one place using the api for Android? Is that possible? May I use the api for W.S even what google says?

Thanks

解决方案

Use this code : read all comment line carefully .

// A class to parse the Google Place Details in JSON format 
    private class ParserTask extends AsyncTask<String, Integer, HashMap<String,String>>{

        JSONObject jObject;
        @Override
        protected HashMap<String,String> doInBackground(String... jsonData) {

            HashMap<String, String> hPlaceDetails = null;
            PlaceDetailsJSONParser placeDetailsJsonParser = new PlaceDetailsJSONParser();

            try{
                // this object give JSON
                jObject = new JSONObject(jsonData[0]);

                // this object give Result
                JSONObject jresult = new JSONObject(jObject[1]);            

                // this object give opening_hours
                JSONObject jopening_hours = new JSONObject(jresult[2]);

                // this object give periods
                JSONObject jperiods = new JSONObject(jopening_hours[2]);



            }catch(Exception e){
                Log.d("Exception",e.toString());
            }
            return jperiods;
        }

        // Executed after the complete execution of doInBackground() method
        @Override
        protected void onPostExecute(JsonObject periods){
                HashMap<String,String> periods;

                // put your condition 
                for(..)
                {
                JsonObject day = new JSONObject(periods[i]);
                    periods.put("key",day.get("day"));

                } 
              }
    }

[0] for Monday and [6] for Sunday

JSON look like https://maps.googleapis.com/maps/api/place/details/json placeid=ChIJKfCbbyyNWTkRAPM1frrO_sM&key=YOUR_API_KEY

Beautify json file : http://jsonviewer.stack.hu/

这篇关于如何使用Google Places API for Android获得opening_hours的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆