デルタ システム ソリューションズ 株式会社

Google Maps APIでお店のランキング表示をしてみると[PHP & GAS編](1/3)

技術情報 PHP Google Apps Script Google Maps 作り方
更新日:2019/04/12

前回は、クライアントサイド・スクリプトであるJavaScriptからGoogle Maps APIを呼び出して、お店ランキング表示をしてみました。
今回は、サーバサイド・スクリプトで同じ機能を実装してみようと思います。

サーバサイド・スクリプトにもいろいろありますが、王道の「PHP」と注目株の「GAS」(Google Apps Script)の2つで組んでみましょう!

【おさらい!】
Google Maps APIでお店のランキング表示をしてみると
Googleには、お店の口コミ情報が集まっていて、5段階評価の星表示もお店選びには役立ちますね。
欲を言うなら、評価順にランキング表示ができたら、サクッと評判のよいお店が探せるのに。
ということで今回は、Google Maps APIを使用して、お店のランキング表示をしてみましょう!
技術情報 JavaScript Google Maps 作り方

サーバサイドでのGoogle Maps APIの呼び出し方

クライアントサイドでは、お店情報を取得するのに「Map JavaScript API」を介して「Places API」を呼び出す、といった回り道が必要でした。
一方で、サーバサイドでは、「Places API」のWebサービスを直接呼び出すことができます。
「Geocoding API」の場合も同様で、Webサービスを直接呼び出します。

従って、サーバサイドでお店情報を検索するのに必要なAPIは
  • Places API
  • Geocoding API
の2つです。
Google API コンソールで、APIの有効化をお忘れなく。


【Geocoding API】住所→緯度・経度

https://maps.googleapis.com/maps/api/geocode/json?key={Google Maps APIのAPIキー}&address={検索場所}
上記のURLにアクセスすると、住所から緯度・経度を変換した結果がJSONデータとして取得できます。

例:「address=横浜中華街」の取得結果

※記事作成時点での結果です。
{
   "results" : [
      {
         "address_components" : [
            {
               "long_name" : "山下町",
               "short_name" : "山下町",
               "types" : [ "political", "sublocality", "sublocality_level_2" ]
            },
            {
               "long_name" : "中区",
               "short_name" : "中区",
               "types" : [ "political", "sublocality", "sublocality_level_1" ]
            },
            {
               "long_name" : "横浜市",
               "short_name" : "横浜市",
               "types" : [ "locality", "political" ]
            },
            {
               "long_name" : "神奈川県",
               "short_name" : "神奈川県",
               "types" : [ "administrative_area_level_1", "political" ]
            },
            {
               "long_name" : "日本",
               "short_name" : "JP",
               "types" : [ "country", "political" ]
            },
            {
               "long_name" : "231-0023",
               "short_name" : "231-0023",
               "types" : [ "postal_code" ]
            }
         ],
         "formatted_address" : "日本、〒231-0023 神奈川県横浜市中区山下町",
         "geometry" : {
            "location" : {
               "lat" : 35.4423591,
               "lng" : 139.6463881
            },
            "location_type" : "GEOMETRIC_CENTER",
            "viewport" : {
               "northeast" : {
                  "lat" : 35.44370808029149,
                  "lng" : 139.6477370802915
               },
               "southwest" : {
                  "lat" : 35.44101011970849,
                  "lng" : 139.6450391197085
               }
            }
         },
         "place_id" : "ChIJ__-Le-9cGGARNY-CTSHwq5A",
         "plus_code" : {
            "compound_code" : "CJRW+WH 日本、神奈川県 横浜市",
            "global_code" : "8Q7XCJRW+WH"
         },
         "types" : [ "establishment", "point_of_interest", "store" ]
      }
   ],
   "status" : "OK"
}


【Places API】緯度・経度→お店情報

https://maps.googleapis.com/maps/api/place/nearbysearch/json?key={Google Maps APIのAPIキー}&location={緯度},{経度}&radius={検索範囲(メートル)}&type={施設の種類}&keyword={検索キーワード}
上記のURLにアクセスすると、指定の検索条件のお店情報がJSONデータとして取得できます。

例:「location=35.4423591,139.6463881&radius=500&type=restaurant&keyword=中華料理」の取得結果

※記事作成時点での結果です。
{
   "html_attributions" : [],
   "next_page_token" : "CrQCLwEAAL-fhmllJiuqr6vOQYq7Xi55PgUyb0h2NCSTG3YneUZh8-FuMEd77YphhNpA6CsWF6COw28oSZd5z5HiB9TeRB1HFtM9kklfaJOAFtvQLg4cKfKFrIZZET7Da0YfsrVrJtUYwFFSoGIc1fzkuRz8BhswYLOXLjUTYC2xY3UvTciRUtLXTZKenWwcDOWQzq4GUI2ZZxx_-57KtdcPv2MLz6JOHl7Ep0pQ1snj5v9fBPS1ytfQufHRTDKufbnfeST7JigN4heJAjg0Y0xxGVuyGi2MA7aesbYK_IsDxr0XrcylZBxq2OsxiQUA8686ewLNxRpmD_UIVYvYLRBlw5ehET7IqN23eZamGLq4djzR7WPwVRwAURC0rBy40CBqutj4CWD6cWMv_iqXgm0c0WaspP4SEGf28w0PsYHjoPzNiSR3Yh0aFI9kVs6mr244SP6kDEm2x_L5or8r",
   "results" : [
      {
         "geometry" : {
            "location" : {
               "lat" : 35.4436144,
               "lng" : 139.6474079
            },
            "viewport" : {
               "northeast" : {
                  "lat" : 35.44496422989272,
                  "lng" : 139.6487577298927
               },
               "southwest" : {
                  "lat" : 35.44226457010728,
                  "lng" : 139.6460580701073
               }
            }
         },
         "icon" : "https://maps.gstatic.com/mapfiles/place_api/icons/restaurant-71.png",
         "id" : "17f8f5ce53048589263237c09d73964e273e6703",
         "name" : "王府井レストラン 宴会 個室 ランチ おすすめ ランキング 中華街 小籠包 人気 飲み放題",
         "opening_hours" : {
            "open_now" : true
         },
         "photos" : [
            {
               "height" : 2976,
               "html_attributions" : [
                  "\u003ca href=\"https://maps.google.com/maps/contrib/103158879894498873291/photos\"\u003eTT SKY\u003c/a\u003e"
               ],
               "photo_reference" : "CmRaAAAA2OayJi3nfHRuoaRe8bE8okWSg05p5P86wkvl8t9Uxns5Px0oDw_OkW6ytszk0r9ITZA5DNGPUsRguBwDXe90TH7xvxfiycJg_OyejllZV3dDuPd8MoFrP2rhceD56V5CEhBd-6MF_nnrb2XTUh_R5-9FGhRzzou8o6GGnZocTyXOiaOgglNAlQ",
               "width" : 3968
            }
         ],
         "place_id" : "ChIJkfSeBONcGGARxORXmw0LTw0",
         "plus_code" : {
            "compound_code" : "CJVW+CX 横浜市、神奈川県",
            "global_code" : "8Q7XCJVW+CX"
         },
         "price_level" : 3,
         "rating" : 3.6,
         "reference" : "ChIJkfSeBONcGGARxORXmw0LTw0",
         "scope" : "GOOGLE",
         "types" : [
            "meal_takeaway",
            "restaurant",
            "point_of_interest",
            "food",
            "establishment"
         ],
         "user_ratings_total" : 65,
         "vicinity" : "横浜市中区山下町185"
      },
      {
         "geometry" : {
            "location" : {
               "lat" : 35.442459,
               "lng" : 139.645917
            },
            "viewport" : {
               "northeast" : {
                  "lat" : 35.44380882989272,
                  "lng" : 139.6472668298927
               },
               "southwest" : {
                  "lat" : 35.44110917010727,
                  "lng" : 139.6445671701073
               }
            }
         },
         "icon" : "https://maps.gstatic.com/mapfiles/place_api/icons/restaurant-71.png",
         "id" : "3d65a8582a37ccf990442749b5d1b38052d44f8d",
         "name" : "横浜中華街 オーダー式食べ放題 皇朝レストラン",
         "opening_hours" : {
            "open_now" : true
         },
         "photos" : [
            {
               "height" : 3104,
               "html_attributions" : [
                  "\u003ca href=\"https://maps.google.com/maps/contrib/101068554336060561809/photos\"\u003eA Google User\u003c/a\u003e"
               ],
               "photo_reference" : "CmRaAAAASRL1CKo3-b9NX7mEYXBsAwhajXzGip1A7a9orkTzQ5xZco39oZPS9RQJMDttDSQFU1n6q2iTS1srN4Nbuy69NsiXIaexiCm5b21zbnW4Y5WfaMWgd-DMPUctEwPrPp3zEhAdLUQGEaTcfPI6O441F5lcGhQGuvHACLLMNrHKrfzPzdHtzils8A",
               "width" : 5520
            }
         ],
         "place_id" : "ChIJ_X6Rd-NcGGARacJZhGM-SwU",
         "plus_code" : {
            "compound_code" : "CJRW+X9 横浜市、神奈川県",
            "global_code" : "8Q7XCJRW+X9"
         },
         "price_level" : 3,
         "rating" : 3.5,
         "reference" : "ChIJ_X6Rd-NcGGARacJZhGM-SwU",
         "scope" : "GOOGLE",
         "types" : [ "restaurant", "point_of_interest", "food", "establishment" ],
         "user_ratings_total" : 320,
         "vicinity" : "横浜市中区山下町138"24"
      },
      {
         "geometry" : {
            "location" : {
               "lat" : 35.443591,
               "lng" : 139.645683
            },
            "viewport" : {
               "northeast" : {
                  "lat" : 35.44494082989272,
                  "lng" : 139.6470328298927
               },
               "southwest" : {
                  "lat" : 35.44224117010727,
                  "lng" : 139.6443331701072
               }
            }
         },
         "icon" : "https://maps.gstatic.com/mapfiles/place_api/icons/restaurant-71.png",
         "id" : "0676e14e0a48152b417e935edb526144cb6a00a1",
         "name" : "聘珍樓 横濱本店( へいちんろう)",
         "opening_hours" : {
            "open_now" : false
         },
         "photos" : [
            {
               "height" : 1960,
               "html_attributions" : [
                  "\u003ca href=\"https://maps.google.com/maps/contrib/109289882130888186340/photos\"\u003eokamoto takaaki\u003c/a\u003e"
               ],
               "photo_reference" : "CmRaAAAAke7KWzeepF6Vic1WoWyqcS9mOYPuWsLqyDTdt2DstQNpCG316ZyUgDPL3spL1XeGYhuxRzGq7yywQF9ALIDGfZC2JOk35l_1jAe_aFEpunx2zCVyzp_ElWRNdMv_zPSBEhCF53gwJ-zdPZt-Wgj29ZwVGhQgKD-sEpDw2p2M_ruBEC3DRtRyaA",
               "width" : 4032
            }
         ],
         "place_id" : "ChIJzVPHQuNcGGARaZvEDqOkEUg",
         "plus_code" : {
            "compound_code" : "CJVW+C7 横浜市、神奈川県",
            "global_code" : "8Q7XCJVW+C7"
         },
         "price_level" : 2,
         "rating" : 4.1,
         "reference" : "ChIJzVPHQuNcGGARaZvEDqOkEUg",
         "scope" : "GOOGLE",
         "types" : [ "restaurant", "point_of_interest", "food", "establishment" ],
         "user_ratings_total" : 617,
         "vicinity" : "横浜市中区山下町149"
      },
      {
         "geometry" : {
            "location" : {
               "lat" : 35.443592,
               "lng" : 139.647377
            },
            "viewport" : {
               "northeast" : {
                  "lat" : 35.44494182989272,
                  "lng" : 139.6487268298927
               },
               "southwest" : {
                  "lat" : 35.44224217010727,
                  "lng" : 139.6460271701073
               }
            }
         },
         "icon" : "https://maps.gstatic.com/mapfiles/place_api/icons/restaurant-71.png",
         "id" : "8acada2928b632bad1b80ab5b8cae20fb5e46e25",
         "name" : "横浜中華街 重慶茶樓",
         "opening_hours" : {
            "open_now" : true
         },
         "photos" : [
            {
               "height" : 2160,
               "html_attributions" : [
                  "\u003ca href=\"https://maps.google.com/maps/contrib/100813084013550994807/photos\"\u003eTadahiro Sano\u003c/a\u003e"
               ],
               "photo_reference" : "CmRaAAAApB53HsW4pAONhfs3zYUUJ63GJxyfi9_AEMlVm52C7s_1EtEgurnqgxtNRMfyPpYvqCF_hOCcvTpDLQkj0OTgSwtLKXG2uU5zv91x0xh-i0m_tc1z3l1dZQvOp90GMVDdEhCx3-Yu70nZz52dvXb1UHReGhQpE-xt0kyt1KHAqkJGMjzB9ul6gQ",
               "width" : 3840
            }
         ],
         "place_id" : "ChIJTRjmBONcGGARZxnN-ht_9Kc",
         "plus_code" : {
            "compound_code" : "CJVW+CX 横浜市、神奈川県",
            "global_code" : "8Q7XCJVW+CX"
         },
         "price_level" : 3,
         "rating" : 3.5,
         "reference" : "ChIJTRjmBONcGGARZxnN-ht_9Kc",
         "scope" : "GOOGLE",
         "types" : [ "restaurant", "point_of_interest", "food", "establishment" ],
         "user_ratings_total" : 192,
         "vicinity" : "横浜市中区山下町185"
      },
      {
         "geometry" : {
            "location" : {
               "lat" : 35.443132,
               "lng" : 139.646863
            },
            "viewport" : {
               "northeast" : {
                  "lat" : 35.44448182989272,
                  "lng" : 139.6482128298927
               },
               "southwest" : {
                  "lat" : 35.44178217010728,
                  "lng" : 139.6455131701073
               }
            }
         },
         "icon" : "https://maps.gstatic.com/mapfiles/place_api/icons/restaurant-71.png",
         "id" : "405b9b1d6a840bb73dd2d4bb17771611772c565d",
         "name" : "菜香新館",
         "opening_hours" : {
            "open_now" : true
         },
         "photos" : [
            {
               "height" : 2160,
               "html_attributions" : [
                  "\u003ca href=\"https://maps.google.com/maps/contrib/117155417713830137587/photos\"\u003e田島栄作\u003c/a\u003e"
               ],
               "photo_reference" : "CmRaAAAAl6-Bjrnh5Tl6S53H4WfIIHHr8x8RslF4iZNm2t5ekFFFO17ovQyYZuz_HwsEqPhGEy5h9KJf2EfEAEH43BpoxZCpFZPH2EYNsuo9us2Qh-jvZGT2bLF3isW9LE-4YWGXEhA4N-qRNxcNt1dG8K1TLgdHGhTakclI_frJ_Uh-MyeMFT0UfiDLdg",
               "width" : 3840
            }
         ],
         "place_id" : "ChIJn89aCeNcGGARRhESdc6Ezqc",
         "plus_code" : {
            "compound_code" : "CJVW+7P 横浜市、神奈川県",
            "global_code" : "8Q7XCJVW+7P"
         },
         "rating" : 4.1,
         "reference" : "ChIJn89aCeNcGGARRhESdc6Ezqc",
         "scope" : "GOOGLE",
         "types" : [ "restaurant", "point_of_interest", "food", "establishment" ],
         "user_ratings_total" : 931,
         "vicinity" : "横浜市中区山下町192"
      },
      {
         "geometry" : {
            "location" : {
               "lat" : 35.4433099,
               "lng" : 139.6463068
            },
            "viewport" : {
               "northeast" : {
                  "lat" : 35.44465972989272,
                  "lng" : 139.6476566298927
               },
               "southwest" : {
                  "lat" : 35.44196007010727,
                  "lng" : 139.6449569701073
               }
            }
         },
         "icon" : "https://maps.gstatic.com/mapfiles/place_api/icons/restaurant-71.png",
         "id" : "142f2767122d405c13655e0f07f4564f9ccc9500",
         "name" : "状元樓",
         "opening_hours" : {
            "open_now" : true
         },
         "photos" : [
            {
               "height" : 4032,
               "html_attributions" : [
                  "\u003ca href=\"https://maps.google.com/maps/contrib/107141057458057181397/photos\"\u003ekoharu osetu\u003c/a\u003e"
               ],
               "photo_reference" : "CmRaAAAAP_alkemHKaoE60dbr56isE8UlvgY4KaKb3Adgsl55jtFsxExGJyKX0RBjw85kMEUtaDm4NZjxpWFk-Rx7kxyeuPzj82Ph3oikZYQew5mcOQEJNzZhHgVHB4C_ZELi1zEEhAuSQXyexcJsWCBVZtn_f2PGhTNRqwp4DIEg9f59ZAKOSKi8ZML3w",
               "width" : 3024
            }
         ],
         "place_id" : "ChIJ6w2lbeNcGGARvWFjbWFI3VE",
         "plus_code" : {
            "compound_code" : "CJVW+8G 横浜市、神奈川県",
            "global_code" : "8Q7XCJVW+8G"
         },
         "price_level" : 3,
         "rating" : 3.9,
         "reference" : "ChIJ6w2lbeNcGGARvWFjbWFI3VE",
         "scope" : "GOOGLE",
         "types" : [ "restaurant", "point_of_interest", "food", "establishment" ],
         "user_ratings_total" : 383,
         "vicinity" : "横浜市中区山下町191"
      },
      {
         "geometry" : {
            "location" : {
               "lat" : 35.4431218,
               "lng" : 139.6449585
            },
            "viewport" : {
               "northeast" : {
                  "lat" : 35.44447162989272,
                  "lng" : 139.6463083298927
               },
               "southwest" : {
                  "lat" : 35.44177197010728,
                  "lng" : 139.6436086701073
               }
            }
         },
         "icon" : "https://maps.gstatic.com/mapfiles/place_api/icons/restaurant-71.png",
         "id" : "81c08bb836de86373e1febd20bc97c469d863d99",
         "name" : "京華樓 中華街大通り店",
         "opening_hours" : {
            "open_now" : true
         },
         "photos" : [
            {
               "height" : 3024,
               "html_attributions" : [
                  "\u003ca href=\"https://maps.google.com/maps/contrib/110398275848446597572/photos\"\u003ei u\u003c/a\u003e"
               ],
               "photo_reference" : "CmRaAAAAwKAl_BQW0hGyTjQ_V91AP7Xlpe_wYDJ5plVTbDmFgILIBIUa7J6jWJRHtPE-wn92basY1U9PSPMHde0wZfT1bLSf-ob_yc07dqU6YV2BU0MrkyCgCunV56tpvHEi-92MEhD6GyJFGTtQlTaFErsG2hCOGhRB2p5xD1rD91wRSbaakGY0kyinKA",
               "width" : 3024
            }
         ],
         "place_id" : "ChIJNQgAneRcGGARu4pMcTls2b8",
         "plus_code" : {
            "compound_code" : "CJVV+6X 横浜市、神奈川県",
            "global_code" : "8Q7XCJVV+6X"
         },
         "price_level" : 3,
         "rating" : 4,
         "reference" : "ChIJNQgAneRcGGARu4pMcTls2b8",
         "scope" : "GOOGLE",
         "types" : [ "restaurant", "point_of_interest", "food", "establishment" ],
         "user_ratings_total" : 111,
         "vicinity" : "横浜市中区山下町145"2"
      },
      {
         "geometry" : {
            "location" : {
               "lat" : 35.44271570000001,
               "lng" : 139.6463856
            },
            "viewport" : {
               "northeast" : {
                  "lat" : 35.44405612989272,
                  "lng" : 139.6476873298928
               },
               "southwest" : {
                  "lat" : 35.44135647010728,
                  "lng" : 139.6449876701073
               }
            }
         },
         "icon" : "https://maps.gstatic.com/mapfiles/place_api/icons/restaurant-71.png",
         "id" : "90c63f7053722dd87ff6296f982e255a8dd9ca47",
         "name" : "景徳鎮",
         "opening_hours" : {
            "open_now" : true
         },
         "photos" : [
            {
               "height" : 3840,
               "html_attributions" : [
                  "\u003ca href=\"https://maps.google.com/maps/contrib/117331752037355751092/photos\"\u003eしょうちゃん\u003c/a\u003e"
               ],
               "photo_reference" : "CmRaAAAAS3-7iJkPHzhLxOhWikYvktC5Uoi5K7iwmLsbjDPS6GHnbXGiPDz4dZZTOegXc0sjZqprN7S3VjYKrRyS2Ni6X7EOxytTTZnZzOh1s7aAnHOaKX8GAfY1VLFt33eh5I59EhBnPJJzzresy7hmG_FuyUXsGhQ-a0xqLfEQ06_uoHzo1f2xeJsL8w",
               "width" : 2160
            }
         ],
         "place_id" : "ChIJf5pbdeNcGGAR8f7jUXw8Akw",
         "plus_code" : {
            "compound_code" : "CJVW+3H 横浜市、神奈川県",
            "global_code" : "8Q7XCJVW+3H"
         },
         "price_level" : 3,
         "rating" : 4,
         "reference" : "ChIJf5pbdeNcGGAR8f7jUXw8Akw",
         "scope" : "GOOGLE",
         "types" : [ "restaurant", "point_of_interest", "food", "establishment" ],
         "user_ratings_total" : 480,
         "vicinity" : "横浜市中区山下町190番地"
      },
      {
         "geometry" : {
            "location" : {
               "lat" : 35.4426059,
               "lng" : 139.6460278
            },
            "viewport" : {
               "northeast" : {
                  "lat" : 35.44395572989272,
                  "lng" : 139.6473776298927
               },
               "southwest" : {
                  "lat" : 35.44125607010728,
                  "lng" : 139.6446779701073
               }
            }
         },
         "icon" : "https://maps.gstatic.com/mapfiles/place_api/icons/restaurant-71.png",
         "id" : "69695743b21dae052cad510b99f3095a9721a464",
         "name" : "福楼",
         "opening_hours" : {
            "open_now" : true
         },
         "photos" : [
            {
               "height" : 1824,
               "html_attributions" : [
                  "\u003ca href=\"https://maps.google.com/maps/contrib/104576537532072552110/photos\"\u003eKo Pan\u003c/a\u003e"
               ],
               "photo_reference" : "CmRaAAAAV-KVPbw2t3QFYy0FussI99GiVRocmBA0NaNo1np2NmEtDIq32PXiCzxCXmCpNrv0g90mfMzL42BQsg8jEKQQkt-1IygDoaaxevNH_6v1ubuqP3dxqYr8jvLhZW_iWtEMEhAoSGawnEPZ_u9IhV7hy7knGhTjzgV04TivLskSn8Jm5sOYFU0CtA",
               "width" : 2736
            }
         ],
         "place_id" : "ChIJFar3neNcGGARpHtWuXSah-4",
         "plus_code" : {
            "compound_code" : "CJVW+2C 横浜市、神奈川県",
            "global_code" : "8Q7XCJVW+2C"
         },
         "price_level" : 3,
         "rating" : 4.1,
         "reference" : "ChIJFar3neNcGGARpHtWuXSah-4",
         "scope" : "GOOGLE",
         "types" : [ "restaurant", "point_of_interest", "food", "establishment" ],
         "user_ratings_total" : 155,
         "vicinity" : "横浜市中区山下町137"26"
      },
      {
         "geometry" : {
            "location" : {
               "lat" : 35.4430596,
               "lng" : 139.6452226
            },
            "viewport" : {
               "northeast" : {
                  "lat" : 35.44440942989272,
                  "lng" : 139.6465724298927
               },
               "southwest" : {
                  "lat" : 35.44170977010728,
                  "lng" : 139.6438727701073
               }
            }
         },
         "icon" : "https://maps.gstatic.com/mapfiles/place_api/icons/restaurant-71.png",
         "id" : "3b1ba31cda92014c2c964fd88ff84895158f9217",
         "name" : "四川麻婆",
         "opening_hours" : {
            "open_now" : true
         },
         "photos" : [
            {
               "height" : 4608,
               "html_attributions" : [
                  "\u003ca href=\"https://maps.google.com/maps/contrib/113919581111531192673/photos\"\u003e本生\u003c/a\u003e"
               ],
               "photo_reference" : "CmRaAAAAaXUa3Fl8_F4CiP3L1k5ENtXyQMw7DzZH4PecbjX8cdDcLbnBoKQijLNPaaL9H4oD4mHvygbeGcHzmAHJ22OSKSU9Pe5gaRHPNDfWIJctNwxnbm9G2Hef9x2xUjSD0sXcEhC5jlfAzYKj6DOXQ9jWIMXIGhTzOfa7fcDfzCUfNPQzP82svCjVQg",
               "width" : 2592
            }
         ],
         "place_id" : "ChIJH6uRfONcGGAR5VgE2v9LOtM",
         "plus_code" : {
            "compound_code" : "CJVW+63 横浜市、神奈川県",
            "global_code" : "8Q7XCJVW+63"
         },
         "price_level" : 3,
         "rating" : 4,
         "reference" : "ChIJH6uRfONcGGAR5VgE2v9LOtM",
         "scope" : "GOOGLE",
         "types" : [ "restaurant", "point_of_interest", "food", "establishment" ],
         "user_ratings_total" : 131,
         "vicinity" : "横浜市中区山下町146"2"
      },
      {
         "geometry" : {
            "location" : {
               "lat" : 35.4404415,
               "lng" : 139.648875
            },
            "viewport" : {
               "northeast" : {
                  "lat" : 35.44179132989272,
                  "lng" : 139.6502248298927
               },
               "southwest" : {
                  "lat" : 35.43909167010727,
                  "lng" : 139.6475251701073
               }
            }
         },
         "icon" : "https://maps.gstatic.com/mapfiles/place_api/icons/restaurant-71.png",
         "id" : "e36a51f19969aacc5925f73a34ce804300944af3",
         "name" : "ドゥ エピセ",
         "opening_hours" : {
            "open_now" : false
         },
         "photos" : [
            {
               "height" : 3024,
               "html_attributions" : [
                  "\u003ca href=\"https://maps.google.com/maps/contrib/112204370389922674764/photos\"\u003eYasuhiko NISHI\u003c/a\u003e"
               ],
               "photo_reference" : "CmRaAAAA2G6v42qEhIpT8AXlvwYxd0-C-PsegZTYBpa2YJ9IqMpGpR7OHES1FAAQngaDIOnLlWGtYwyGfvTZA7BaK42txI7ET6W1RutgH9wsTrh0OXOSnv-Cbi3vRVEu_GHMfrU3EhB_KUlaHVc86WqUVcG3FLkCGhSstUrPGRY6ddPvHwtjIASWhIOGwQ",
               "width" : 4032
            }
         ],
         "place_id" : "ChIJT4ZflOFcGGARsP6e0g6WaSw",
         "plus_code" : {
            "compound_code" : "CJRX+5G 横浜市、神奈川県",
            "global_code" : "8Q7XCJRX+5G"
         },
         "price_level" : 3,
         "rating" : 4.3,
         "reference" : "ChIJT4ZflOFcGGARsP6e0g6WaSw",
         "scope" : "GOOGLE",
         "types" : [ "restaurant", "point_of_interest", "food", "establishment" ],
         "user_ratings_total" : 29,
         "vicinity" : "横浜市中区元町2丁目88 元町シエテ B1F"
      },
      {
         "geometry" : {
            "location" : {
               "lat" : 35.4437861,
               "lng" : 139.6448011
            },
            "viewport" : {
               "northeast" : {
                  "lat" : 35.44513592989272,
                  "lng" : 139.6461509298927
               },
               "southwest" : {
                  "lat" : 35.44243627010727,
                  "lng" : 139.6434512701072
               }
            }
         },
         "icon" : "https://maps.gstatic.com/mapfiles/place_api/icons/restaurant-71.png",
         "id" : "036457a348863d0901b428a17a396a53c57a63fd",
         "name" : "萬珍樓 點心舗",
         "opening_hours" : {
            "open_now" : true
         },
         "photos" : [
            {
               "height" : 3024,
               "html_attributions" : [
                  "\u003ca href=\"https://maps.google.com/maps/contrib/104980178536663562048/photos\"\u003eA Google User\u003c/a\u003e"
               ],
               "photo_reference" : "CmRaAAAA96n_l6zz8ZAULWRW0TTeAqn9L6etzX7MqETtM-XIX4qwvZk20G2S5ejYs4eBiJnSmRfoueROCLa65HfVDn7fEIz4ERDEsnx3s0EHbejpdQg-8II_LRVfKtKcD-zHCuEoEhAls3TxLcG7CdJlHhc8_UqgGhT0OFARRprIAN5P3J-F4guhswW2pA",
               "width" : 4032
            }
         ],
         "place_id" : "ChIJ2wwIsuRcGGARi5GOlmnBExY",
         "plus_code" : {
            "compound_code" : "CJVV+GW 横浜市、神奈川県",
            "global_code" : "8Q7XCJVV+GW"
         },
         "price_level" : 2,
         "rating" : 4.2,
         "reference" : "ChIJ2wwIsuRcGGARi5GOlmnBExY",
         "scope" : "GOOGLE",
         "types" : [ "restaurant", "point_of_interest", "food", "establishment" ],
         "user_ratings_total" : 479,
         "vicinity" : "横浜市中区山下町156"
      },
      {
         "geometry" : {
            "location" : {
               "lat" : 35.443399,
               "lng" : 139.644436
            },
            "viewport" : {
               "northeast" : {
                  "lat" : 35.44474882989272,
                  "lng" : 139.6457858298927
               },
               "southwest" : {
                  "lat" : 35.44204917010728,
                  "lng" : 139.6430861701073
               }
            }
         },
         "icon" : "https://maps.gstatic.com/mapfiles/place_api/icons/restaurant-71.png",
         "id" : "4f583d7ec8add975f52bf22c29fa150520399a60",
         "name" : "萬珍樓本店",
         "opening_hours" : {
            "open_now" : true
         },
         "photos" : [
            {
               "height" : 4032,
               "html_attributions" : [
                  "\u003ca href=\"https://maps.google.com/maps/contrib/113372768025025998448/photos\"\u003eA Google User\u003c/a\u003e"
               ],
               "photo_reference" : "CmRaAAAARQVsBKF4tWoO82ARylxHNN4--Jb08QzucOc9yKz6bwQuPcZdIuIF2IomxpVuh49mqoIxgDRs49W5YbuBe1UWMsJ5f607qWceLzHFvGQjkN1a5SzJMTqBB1ZEHZ0iZFymEhAWwtOid8MxZnrCpSpAJJRLGhRFRA9wthGiWLRH2sFyGLRo8uKbCQ",
               "width" : 3024
            }
         ],
         "place_id" : "ChIJN5Rzu-RcGGARHASwo8SYs3w",
         "plus_code" : {
            "compound_code" : "CJVV+9Q 横浜市、神奈川県",
            "global_code" : "8Q7XCJVV+9Q"
         },
         "price_level" : 2,
         "rating" : 4.3,
         "reference" : "ChIJN5Rzu-RcGGARHASwo8SYs3w",
         "scope" : "GOOGLE",
         "types" : [ "restaurant", "point_of_interest", "food", "establishment" ],
         "user_ratings_total" : 760,
         "vicinity" : "横浜市中区山下町153"
      },
      {
         "geometry" : {
            "location" : {
               "lat" : 35.4417908,
               "lng" : 139.6481679
            },
            "viewport" : {
               "northeast" : {
                  "lat" : 35.44314062989272,
                  "lng" : 139.6495177298927
               },
               "southwest" : {
                  "lat" : 35.44044097010728,
                  "lng" : 139.6468180701073
               }
            }
         },
         "icon" : "https://maps.gstatic.com/mapfiles/place_api/icons/restaurant-71.png",
         "id" : "25287688b1a629cd3ac8ed3b0603078d78e1421c",
         "name" : "好記園",
         "opening_hours" : {
            "open_now" : false
         },
         "photos" : [
            {
               "height" : 417,
               "html_attributions" : [
                  "\u003ca href=\"https://maps.google.com/maps/contrib/100969567798594106337/photos\"\u003e好記園 台湾料理\u003c/a\u003e"
               ],
               "photo_reference" : "CmRaAAAAkem5_kI6x6oq7V-Gb3wjz-AqBkygQIjtO138C2HsRjmunOwDUGF060YHXza-taz9we6JNTgV1QvFMjSNtYIFc3Kd6NjvvZaXrNkcgx9EBsFmFr-5v_14PwWCnSfEE-rREhDCbKgLRDFE5aBfzYapS89vGhQT_7Z9IkOUanPZNhIzh-ItCQdwCA",
               "width" : 740
            }
         ],
         "place_id" : "ChIJNdVrMOJcGGAR1-StXbqg-6g",
         "plus_code" : {
            "compound_code" : "CJRX+P7 横浜市、神奈川県",
            "global_code" : "8Q7XCJRX+P7"
         },
         "rating" : 4.2,
         "reference" : "ChIJNdVrMOJcGGAR1-StXbqg-6g",
         "scope" : "GOOGLE",
         "types" : [ "restaurant", "point_of_interest", "food", "establishment" ],
         "user_ratings_total" : 74,
         "vicinity" : "横浜市中区山下町 106 Kanagawa"
      },
      {
         "geometry" : {
            "location" : {
               "lat" : 35.443297,
               "lng" : 139.643206
            },
            "viewport" : {
               "northeast" : {
                  "lat" : 35.44464682989272,
                  "lng" : 139.6445558298927
               },
               "southwest" : {
                  "lat" : 35.44194717010728,
                  "lng" : 139.6418561701073
               }
            }
         },
         "icon" : "https://maps.gstatic.com/mapfiles/place_api/icons/restaurant-71.png",
         "id" : "af0d2ee571c4f39967cc3d84af71d3056a71854e",
         "name" : "横浜中華街 四川・福建料理 福満園 本店 | 麻婆豆腐 宴会",
         "opening_hours" : {
            "open_now" : true
         },
         "photos" : [
            {
               "height" : 2160,
               "html_attributions" : [
                  "\u003ca href=\"https://maps.google.com/maps/contrib/108520689752341877310/photos\"\u003eA Google User\u003c/a\u003e"
               ],
               "photo_reference" : "CmRaAAAAMg7WNhR42QLbrW6kosn2SP9e5ybYyY8HSx_IIfyF4NuSuGLanu7DyocvX3hLnGeh_1WCq8gxj_KinD3308NIM4kdc_fhh8DDmpPEQKAIKxOs1kymzkoia0pWJES_oEQDEhDQQWD_oQGLY1fpjw62i5RGGhRyoL_M7WDsH-vWFx91_VRUBUlbpg",
               "width" : 3840
            }
         ],
         "place_id" : "ChIJ-3cRxeRcGGARKJ5K5RB62kE",
         "plus_code" : {
            "compound_code" : "CJVV+87 横浜市、神奈川県",
            "global_code" : "8Q7XCJVV+87"
         },
         "price_level" : 3,
         "rating" : 3.9,
         "reference" : "ChIJ-3cRxeRcGGARKJ5K5RB62kE",
         "scope" : "GOOGLE",
         "types" : [ "restaurant", "point_of_interest", "food", "establishment" ],
         "user_ratings_total" : 152,
         "vicinity" : "横浜市中区山下町中区 200 トキワビル 1F"
      },
      {
         "geometry" : {
            "location" : {
               "lat" : 35.4433167,
               "lng" : 139.6470514
            },
            "viewport" : {
               "northeast" : {
                  "lat" : 35.44466652989272,
                  "lng" : 139.6484012298927
               },
               "southwest" : {
                  "lat" : 35.44196687010728,
                  "lng" : 139.6457015701072
               }
            }
         },
         "icon" : "https://maps.gstatic.com/mapfiles/place_api/icons/restaurant-71.png",
         "id" : "195d4373e628cc8e11e182d3afd3fecab1b5f60a",
         "name" : "華正樓 本店",
         "opening_hours" : {
            "open_now" : true
         },
         "photos" : [
            {
               "height" : 2160,
               "html_attributions" : [
                  "\u003ca href=\"https://maps.google.com/maps/contrib/102920604083440358033/photos\"\u003eA Google User\u003c/a\u003e"
               ],
               "photo_reference" : "CmRaAAAAladdh7G55wTLvANgOmq-FqLlCqMKrrreeElp3nNzJo_J7ojM98Sao3RG0T109Ichw0agoSbtN1y576rWpkVZKM2N2AIqwLzrUQRbjqzGrULsa-Gk6tAvN1rDh02v9IIFEhCwqge77vcYm1pAX40B-lSlGhTNk5RpcpGHK1onFruwurdRA1YUNA",
               "width" : 3840
            }
         ],
         "place_id" : "ChIJy6prD-NcGGARCBwxrt3GsLM",
         "plus_code" : {
            "compound_code" : "CJVW+8R 横浜市、神奈川県",
            "global_code" : "8Q7XCJVW+8R"
         },
         "price_level" : 2,
         "rating" : 4.2,
         "reference" : "ChIJy6prD-NcGGARCBwxrt3GsLM",
         "scope" : "GOOGLE",
         "types" : [ "restaurant", "point_of_interest", "food", "establishment" ],
         "user_ratings_total" : 175,
         "vicinity" : "横浜市中区山下町186"
      },
      {
         "geometry" : {
            "location" : {
               "lat" : 35.4423087,
               "lng" : 139.6468433
            },
            "viewport" : {
               "northeast" : {
                  "lat" : 35.44365852989272,
                  "lng" : 139.6481931298927
               },
               "southwest" : {
                  "lat" : 35.44095887010727,
                  "lng" : 139.6454934701073
               }
            }
         },
         "icon" : "https://maps.gstatic.com/mapfiles/place_api/icons/restaurant-71.png",
         "id" : "f57c66f49a46a4635dd6372601e3fd8800b4c687",
         "name" : "秀味園",
         "opening_hours" : {
            "open_now" : true
         },
         "photos" : [
            {
               "height" : 3120,
               "html_attributions" : [
                  "\u003ca href=\"https://maps.google.com/maps/contrib/103215763137282912753/photos\"\u003eDY, ナム Nam\u003c/a\u003e"
               ],
               "photo_reference" : "CmRaAAAAoZEDFZBrlSPCgWA3Yzfz44YSmAo8JNb7RYSZImxBv82J0dCXj7uyW6ZObbeWlI7fJ5GZxatu8ZpdOPdOdiAbaN-wRj31v_crh7iMBmmslDma1hWXnNqBJbMf0oxDVz-2EhDCZG_75QrE3UIGqYUtXfdxGhStK8pRQLR0rvFBdBZ63wbebPTDHw",
               "width" : 4160
            }
         ],
         "place_id" : "ChIJG4s9uuNcGGARXvYcJB3ozTM",
         "plus_code" : {
            "compound_code" : "CJRW+WP 横浜市、神奈川県",
            "global_code" : "8Q7XCJRW+WP"
         },
         "price_level" : 2,
         "rating" : 3.7,
         "reference" : "ChIJG4s9uuNcGGARXvYcJB3ozTM",
         "scope" : "GOOGLE",
         "types" : [ "restaurant", "point_of_interest", "food", "establishment" ],
         "user_ratings_total" : 220,
         "vicinity" : "横浜市中区山下町134"
      },
      {
         "geometry" : {
            "location" : {
               "lat" : 35.4427171,
               "lng" : 139.6481692
            },
            "viewport" : {
               "northeast" : {
                  "lat" : 35.44406692989271,
                  "lng" : 139.6495190298927
               },
               "southwest" : {
                  "lat" : 35.44136727010726,
                  "lng" : 139.6468193701073
               }
            }
         },
         "icon" : "https://maps.gstatic.com/mapfiles/place_api/icons/restaurant-71.png",
         "id" : "a1f96bfb27cbdc6ece17190ca5ce67908bcac4e1",
         "name" : "横浜中華街 ランチ・ディナー《廣翔記 新館》",
         "opening_hours" : {
            "open_now" : true
         },
         "photos" : [
            {
               "height" : 2160,
               "html_attributions" : [
                  "\u003ca href=\"https://maps.google.com/maps/contrib/102209441987906501339/photos\"\u003e犬飼美穂\u003c/a\u003e"
               ],
               "photo_reference" : "CmRaAAAAmuOYt6PtTwfJ4HjbtjvrqgCnO77fUdSR0KGwMc4XOdEo2mM1i_LoGWq9MoX7P5QaUIhTM-GLOpnRtZD7dePTgFuS1w2tFgSPmMFXddVghTtvyG10IYKhQ9vVp6PySLG1EhD-M8RcqBF26UsaqbPnIGkMGhRbNzO0xal5BfEONWQ4dt5eBZXaIg",
               "width" : 3840
            }
         ],
         "place_id" : "ChIJHdJrTuJcGGARf6WCIwNdAts",
         "plus_code" : {
            "compound_code" : "CJVX+37 横浜市、神奈川県",
            "global_code" : "8Q7XCJVX+37"
         },
         "price_level" : 3,
         "rating" : 3.7,
         "reference" : "ChIJHdJrTuJcGGARf6WCIwNdAts",
         "scope" : "GOOGLE",
         "types" : [ "restaurant", "point_of_interest", "food", "establishment" ],
         "user_ratings_total" : 124,
         "vicinity" : "横浜市中区山下町97 一石屋ビル1・2F"
      },
      {
         "geometry" : {
            "location" : {
               "lat" : 35.4431301,
               "lng" : 139.6460501
            },
            "viewport" : {
               "northeast" : {
                  "lat" : 35.44447992989272,
                  "lng" : 139.6473999298927
               },
               "southwest" : {
                  "lat" : 35.44178027010727,
                  "lng" : 139.6447002701073
               }
            }
         },
         "icon" : "https://maps.gstatic.com/mapfiles/place_api/icons/restaurant-71.png",
         "id" : "0bd13675c617eb7a79a9bab4f9f31224c5e26ac0",
         "name" : "状元郷 (じょうげんきょう)",
         "opening_hours" : {
            "open_now" : false
         },
         "photos" : [
            {
               "height" : 3000,
               "html_attributions" : [
                  "\u003ca href=\"https://maps.google.com/maps/contrib/114346483359394245176/photos\"\u003etoko teke\u003c/a\u003e"
               ],
               "photo_reference" : "CmRaAAAAOdHMC5RlhPu0ghBpiRonBlUHkUysBGZno5MfuYoMp_vJm4aZm4LjrmsKaIVKOeSEcFSUjJfDPgipiLT8pRIGSKhDJQBcIQa7tC2_7C3_sWqxGpPNZDdOG_JRW_FrEoGHEhCKSrUIqWa9Ok8SeZKQuh42GhQx5FME3u8y9_xmqCR606HwPPbJ2Q",
               "width" : 5333
            }
         ],
         "place_id" : "ChIJwcgnbuNcGGAR4Btc9SgKF_U",
         "plus_code" : {
            "compound_code" : "CJVW+7C 横浜市、神奈川県",
            "global_code" : "8Q7XCJVW+7C"
         },
         "price_level" : 3,
         "rating" : 4.2,
         "reference" : "ChIJwcgnbuNcGGAR4Btc9SgKF_U",
         "scope" : "GOOGLE",
         "types" : [ "restaurant", "point_of_interest", "food", "establishment" ],
         "user_ratings_total" : 79,
         "vicinity" : "横浜市中区山下町148"
      },
      {
         "geometry" : {
            "location" : {
               "lat" : 35.4440751,
               "lng" : 139.6468094
            },
            "viewport" : {
               "northeast" : {
                  "lat" : 35.44542492989272,
                  "lng" : 139.6481592298927
               },
               "southwest" : {
                  "lat" : 35.44272527010728,
                  "lng" : 139.6454595701073
               }
            }
         },
         "icon" : "https://maps.gstatic.com/mapfiles/place_api/icons/restaurant-71.png",
         "id" : "c603851350951511926608f5d97d5550ac6ea148",
         "name" : "重慶飯店 新館",
         "opening_hours" : {
            "open_now" : false
         },
         "photos" : [
            {
               "height" : 3096,
               "html_attributions" : [
                  "\u003ca href=\"https://maps.google.com/maps/contrib/114751693290921154024/photos\"\u003e小林美和\u003c/a\u003e"
               ],
               "photo_reference" : "CmRaAAAAd4huTGLyZrCzJw_upH92nduHtWqlEc8zZ25k2y2VseT3MQLcX4Kt8T0kc9Dgq6baq9EJ8fcivv6myry-vEJ1uH436Z_bjPeTOaNKvJu487FnU3JnJ8WwFqGWV_l5iVM3EhAi0C6UM_hmw1R9OyqbSap5GhQkO5dcDyStUJCII1qG0hAY5fVc4w",
               "width" : 5504
            }
         ],
         "place_id" : "ChIJw1hGovxcGGARXJ85TQqTmkk",
         "plus_code" : {
            "compound_code" : "CJVW+JP 横浜市、神奈川県",
            "global_code" : "8Q7XCJVW+JP"
         },
         "price_level" : 3,
         "rating" : 4.1,
         "reference" : "ChIJw1hGovxcGGARXJ85TQqTmkk",
         "scope" : "GOOGLE",
         "types" : [ "restaurant", "point_of_interest", "food", "establishment" ],
         "user_ratings_total" : 296,
         "vicinity" : "横浜市中区山下町77"
      }
   ],
   "status" : "OK"
}

nearbysearchの結果は、JavaScriptでの取得結果と同様に「最大60件取得可能で、20件ずつ取得される」という仕様があります。
次ページの情報を取得するには、取得したnext_page_tokenの値を使って、Webサービスを再アクセスします。

【Places API】お店情報の次ページ情報を取得

https://maps.googleapis.com/maps/api/place/nearbysearch/json?key={Google Maps APIのAPIキー}&pagetoken={取得したnext_page_tokenの値}
この時、「連続してアクセスすると上手く取得できない」ので、2秒程間隔をおいてください。
(JavaScriptで次ページ取得する時は1秒程の間隔で大丈夫でしたが、サーバサイドでは2秒程の間隔がいるようです。)


さて、ちなみに・・・
サーバサイド・スクリプトでは「WebサービスのURLにアクセスすれば結果が取得できる」と述べましたが、それならばクライアントサイド・スクリプトのJavaScriptでもAjaxを使えばWebサービスのURLにアクセスできるのでは?と思われた方もいるでしょう。
はい、私も最初はそう思いました。
しかし、試してみれば分かりますが、JavaScriptからではエラーとなって結果が取得できません。

理由は、「JavaScriptでは、別ドメインのサイトからTEXT,XML,JSONデータを取得できない」という制約があるからです。(JavaScriptのクロスドメイン問題と言います。)
回避方法として、「JSONP」という形式でメッセージを受け渡しする方法があるのですが、Places APIやGeocoding APIではJSONPに対応していないようです。
では、実際にサーバサイド・スクリプトの「PHP」と「GAS」で、お店ランキング表示を実装してみましょう!

1

あなたへのおすすめ記事