IBM Worklight - 适配器过程响应从Google Places返回“零结果”

时间:2014-02-12 15:37:11

标签: ibm-mobilefirst google-places-api worklight-adapters

当我使用印度纬度和经度调用HTTP适配器来搜索食物,商场等任何服务时,我获得状态“ZERO RESULTS”。

这是我的适配器实现:

 function getGooglePlaces(location,name) {

    var input = {
        method : 'get',
        returnedContentType : 'json',
        path : 'maps/api/place/search/json',
        headers: {
            Host: 'maps.googleapis.com'
        },
        parameters : {
            'key'       :   My Key,
            'location'  :  location,
            'radius'    :   '10000',
            'sensor'    :   'false',
            'name'      :  name 
        }
    };

    var response = WL.Server.invokeHttp(input); 
    return response;

}

}

印度坐标的JSON响应 结果是搜索的地点数组

{
 "html_attributions": [
  ],
 "isSuccessful": true,
 "responseHeaders": {
  "Alternate-Protocol": "443:quic",
  "Cache-Control": "public, max-age=300",
  "Content-Type": "application\/json; charset=UTF-8",
  "Date": "Wed, 12 Feb 2014 15:06:33 GMT",
  "Expires": "Wed, 12 Feb 2014 15:11:33 GMT",
  "Server": "mafe",
  "Transfer-Encoding": "chunked",
  "Vary": "Accept-Language",
  "X-Frame-Options": "SAMEORIGIN",
  "X-XSS-Protection": "1; mode=block"
   },
  "responseTime": 609,
  "results": [
   ],
   "status": "ZERO_RESULTS",
   "statusCode": 200,
   "statusReason": "OK",
   "totalTime": 609
   }

1 个答案:

答案 0 :(得分:0)

我使用了以下内容并使用Worklight适配器获得了有效的响应。

  • 请注意,我作为参数对象的一部分传递了namelocation,而不是像您那样(仅为了简化)
  • 我为" restaurant"
  • 添加了type参数
  • 我增加了radius

有了上述内容,我得到了结果 在我看来这是一个调整请求参数的问题。这里没有与Worklight适配器相关的任何内容,因为它可以工作。

<强> GooglePlaces-impl.js

function getPlaces() {
    var input = {
            method : 'get',
            returnedContentType : 'json',
            path : 'maps/api/place/search/json',
            headers: {
                Host: 'maps.googleapis.com'
            },
            parameters : {
                'key'       : 'make-sure-to-place-here-your-SERVER-KEY-generated-by-Google-GCM-console',
                'location'  : '27.173033, 78.042133',
                'radius'    : '30000',
                'sensor'    : 'false',
                'name'      : 'Taj Mahal',
                'type'      : 'restaurant',
            }
        };

        var response = WL.Server.invokeHttp(input);
        return response;
}

程序回复

{
   "html_attributions": [
   ],
   "isSuccessful": true,
   "responseHeaders": {
      "Alternate-Protocol": "443:quic",
      "Cache-Control": "public, max-age=300",
      "Content-Type": "application\/json; charset=UTF-8",
      "Date": "Fri, 14 Mar 2014 05:45:41 GMT",
      "Expires": "Fri, 14 Mar 2014 05:50:41 GMT",
      "Server": "mafe",
      "Transfer-Encoding": "chunked",
      "Vary": "Accept-Language",
      "X-Frame-Options": "SAMEORIGIN",
      "X-XSS-Protection": "1; mode=block"
   },
   "responseTime": 662,
   "results": [
      {
         "geometry": {
            "location": {
               "lat": 27.175015,
               "lng": 78.042155
            }
         },
         "icon": "http:\/\/maps.gstatic.com\/mapfiles\/place_api\/icons\/generic_business-71.png",
         "id": "dcc9586b99ab0f0471fccecbe2dbb40fdc1fc2b5",
         "name": "Taj Mahal",
         "photos": [
            {
               "height": 853,
               "html_attributions": [
               ],
               "photo_reference": "CnRnAAAAojrNNKpH2yqjmiph_kNBxiT5DaK_g3N05YtE_mPP5tBrYD8XjyAAz_xEvWAJymfGOeeOTlVgzFUxUeOMQspvoPGogDQyWomDeZsNP7XEW3JsmzmYakDk_vyJBwajiamhluypx6rCDqDCnBWb6JnCLBIQRuBibftSN9xruu2eeZEm5xoUksG5kyFbtZULWpZceNvNhyl72tQ",
               "width": 1280
            }
         ],
         "rating": 4.6,
         "reference": "CnRrAAAA8n6I_Dnlm9UzwTiaTntjcxR-FysL5Ya26Fdcsdb48XOIxiJDGdd3AiK6iUUti41d1BQ1XnBfZoVMKWZ5QOyVZAW8QyH-xqSY8eaQXuxH0atjzXtuaplht-ww76JtbxQLkJ4SUtFrmrs7ZjmZn-_RhBIQmYTB0_yGd_4hm2bHoIKt5xoULaBq-FsZo51jFdxLV377nHM0cCI",
         "types": [
            "establishment"
         ],
         "vicinity": "Agra"
      },
     ...
     ...
     "status": "OK",
       "statusCode": 200,
       "statusReason": "OK",
       "totalTime": 1088
    }