Google商家信息照片:将photo_reference转换为照片网址

时间:2015-09-20 14:33:05

标签: android json google-maps google-places-api

我正在尝试构建一个可以显示附近地点的位置名称及其照片的应用。我正在使用Google Places API。

我想快速将photo_reference转换为照片网址。

目前,如果你进行附近的搜索,你会在附近的20个地点找回这个json(我刚刚粘贴了2个位置,因为json太长了):

{
   "html_attributions" : [
      "Listings by \u003ca href=\"http://www.easyinfo.co.za/\"\u003eEasyinfo.co.za\u003c/a\u003e"
   ],
   "next_page_token" : "CvQB7AAAAEIeM4orJZv2oOV0Lt_mhGBbkvvJIyOwjcHeStpcC5E6fR7pNHw4VsS6cMSKzFRtyjr2LQ67GSvZwFGxw8f72sxwO6NggFNsSyakjO9bKovKpjCn4-uHoQyXESaxMqMci1fet-n9EJEp-VoBVXv-iIb_TvSO26iIXkGUeO-09-19ucYirFahOaNF0pp8ttod59XWgsLPs5r1PnkakrYj5JBgawP83T0ZMwIY52oViQJNGvR6_Bpf73dK68iUnj24w5QNZOql6uAlvFAg-BXs5FKjTWvQO0nR5woo5mJjDzYvbaxQkpMqFQ-BMEnZ3RX10xIQ3twWZWnygJl78DhqZH1DkBoUdcq5qakPBsg1QAn6BdcqdrQFz2g",
   "results" : [
      {
         "geometry" : {
            "location" : {
               "lat" : -26.2020253,
               "lng" : 28.0500779
            },
            "viewport" : {
               "northeast" : {
                  "lat" : -26.2003339,
                  "lng" : 28.054075
               },
               "southwest" : {
                  "lat" : -26.2041059,
                  "lng" : 28.0470949
               }
            }
         },
         "icon" : "https://maps.gstatic.com/mapfiles/place_api/icons/geocode-71.png",
         "id" : "0765607c0fdb4fae92e59390aff8e9501e98e59c",
         "name" : "Fashion District",
         "place_id" : "ChIJ2Vn0h5wOlR4RsOSteUYYM6g",
         "reference" : "CpQBkAAAADboZMmtzHTuxZ85pPFK1fr-V0QslLUKBr8QZssBme4qcqLqs7SvrW-L2lJZg3S0PBYTGzuBU8M1F-Ll72tOdto-hfnxOCBOFfVIQEYe264r-IbWZjiFbuqOHBtU5z99jo3NrTxI29MvE8ogUYccX8FukX8eoAcpKti3Ik2VLvDziRKArf2EDy-6CtSbxeCnthIQyHx09QzBQ-pWEelLd6tCsxoUklzTqP7XbT6WbDCbIa42k1R4Iic",
         "scope" : "GOOGLE",
         "types" : [ "neighborhood", "political" ],
         "vicinity" : "Johannesburg"
      },
      {
         "geometry" : {
            "location" : {
               "lat" : -26.205586,
               "lng" : 28.046573
            }
         },
         "icon" : "https://maps.gstatic.com/mapfiles/place_api/icons/restaurant-71.png",
         "id" : "671355d0ee1b5b0bbc1556321cea85ca164601de",
         "name" : "KFC Carlton Centre",
         "opening_hours" : {
            "open_now" : true,
            "weekday_text" : []
         },
         "photos" : [
            {
               "height" : 296,
               "html_attributions" : [
                  "\u003ca href=\"https://maps.google.com/maps/contrib/106295947298714161198\"\u003eKFC Carlton Centre\u003c/a\u003e"
               ],
               "photo_reference" : "CmRdAAAAHcsAE2aiv5lIxLEo0c9xMUmH-chXoAeq6yrFPw5uy7LdppAMxBmg8_yvG9y9qaXqsH-IrcPsBD6QQvsfZnpml3U5zgh93nTbm5WONnYmutBSltIr9FwuK-awm8l1vyKeEhD9AqZpJwFLIWms2GeZGPR2GhSPp1JyAU_6_s1Im1_oH5tB4IjyXQ",
               "width" : 607
            }
         ],
         "place_id" : "ChIJTQABc5kOlR4RAzBKVJ-lZNo",
         "price_level" : 1,
         "rating" : 3.7,
         "reference" : "CnRmAAAAyOipUqSqkrpsKw96nu3YnT72kF2Yj_FWAd3wJkzM6a73ZZu8AJIXGsS-EmvugVGsgcEEcadiPfLJCdX3_molaMarh-sox9sIDp5M9LE6xhE1U-6WMXarQEjNu6_ATfQMdaR0nJPpxCX_AS2vbym1wBIQAA9yUjeeEXHF-HDsjTj9kBoUvRoUMWlNtyY30v0iWqMUzstMHOE",
         "scope" : "GOOGLE",
         "types" : [ "restaurant", "food", "point_of_interest", "establishment" ],
         "vicinity" : "Commissioner Street, Carlton Centre, Johannesburg"
      }

要获取照片网址,您必须为json中的20个photo_reference中的每一个调用以下内容 - 这些对Google服务器的调用需要花费大量时间才能返回,因为您单独呼叫服务器20次:< / p>

  

https://maps.googleapis.com/maps/api/place/photo?maxwidth=400&photoreference=CmRdAAAAHcsAE2aiv5lIxLEo0c9xMUmH-chXoAeq6yrFPw5uy7LdppAMxBmg8_yvG9y9qaXqsH-IrcPsBD6QQvsfZnpml3U5zgh93nTbm5WONnYmutBSltIr9FwuK-awm8l1vyKeEhD9AqZpJwFLIWms2GeZGPR2GhSPp1JyAU_6_s1Im1_oH5tB4IjyXQ&key=API-KEY

每次调用都会返回与此类似的内容,即图像的实际网址 - 如果单击下面的链接,则会转到实际图片。

  

https://lh3.googleusercontent.com/-B8FWOhhu2_k/VTdYJeFjRhI/AAAAAAAAAD8/JSJamjx4XyA/s1600-w400/

我认为这是一种非常低效的方式来获取地方照片的链接,我的其余API调用有时会在10秒后返回。有效的方法吗?

0 个答案:

没有答案