Getting started with Google Places API

A quick introduction to Google Places API. Learn how to search for places within a certain vacinity and then retrieve place details (including Google reviews).

Posted
5 February 2018

The Google Places API is a web service that returns information about places. You can find out more information about the API here:

https://developers.google.com/places/web-service/intro

Before you can get started with the Google Places API, you need an API key. This API key is sent with every request you make to the Google Places API and allows Google to track your usage of the API. You can get an API key here:

https://developers.google.com/places/web-service/get-api-key

There is a very generous limit on the number of requests you can make to the Google Places API, which is 150,000 requests per 24 hour period. More information on usage limits can be found here:

https://developers.google.com/places/web-service/usage

To prevent other people from using your key and consuming your quota, you can limit the IP addresses that can use your API key to send requests by visiting the Google API Console:

https://console.developers.google.com/projectselector/apis/credentials

In order to retrieve details that Google has stored about a place, you first need to determine that place's unique identifier. To do this, you can issue a place search as described here:

https://developers.google.com/places/web-service/search

To execute a place search, you must specify a location (latitude and longitude). If you have the postcode (ZIP Code or equivalent) of the place whose identifier you are searching for, you can retrieve the corresponding latitude and longitude by opening up your web browser, going to Google Maps, searching for the postcode and examining the resulting URL that appears in your browser address bar. A search for location SE1 2HB reveals the following URL:

https://www.google.co.uk/maps/place/Hay's+Ln,+London+SE1+2HB/@51.5056222,-0.0870083,17z/data=!3m1!4b1!4m5!3m4!1s0x4876035047490039:0xb6fd906f38d69140!8m2!3d51.5056097!4d-0.0849144

Looking closely at the above URL, you can see that the latitude and longitude of SE1 2HB are shown directly after the @ symbol: 51.5056222,-0.0870083. So, to search for information about mortgage broker Domus Finance Ltd, located at SE21 2HB, the following request could be executed (you must substitute your own API key):

https://maps.googleapis.com/maps/api/place/nearbysearch/json?key=YourAPIKeyGoesHere&location=51.5056222,-0.0870083&rankby=distance&keyword=domus%20finance%20ltd

When the place search URL specified above is executed (either via code or by entering the URL into the address bar of a web browser), JSON is returned that contains the place identifier (ChIJ_0BrEG4OdkgR5uaXg3OK0as) of Domus Finance Ltd:

{
   "html_attributions" : [],
   "results" : [
      {
         "geometry" : {
            "location" : {
               "lat" : 51.5055825,
               "lng" : -0.0848951
            },
            "viewport" : {
               "northeast" : {
                  "lat" : 51.50687752989273,
                  "lng" : -0.08345382010727778
               },
               "southwest" : {
                  "lat" : 51.50417787010728,
                  "lng" : -0.08615347989272222
               }
            }
         },
         "icon" : "https://maps.gstatic.com/mapfiles/place_api/icons/generic_business-71.png",
         "id" : "6ab3107787593d2a6346a82474573c099df3adbb",
         "name" : "Domus Finance Ltd",
         "opening_hours" : {
            "open_now" : true,
            "weekday_text" : []
         },
         "photos" : [
            {
               "height" : 2988,
               "html_attributions" : [ "Photos are copyrighted by their owners" ],
               "photo_reference" : "CmRaAAAA2tYUNw842DCQ2r8OrgYqTkKa9WYt_oFA4F1VNnFLCUrET4FdhLiK4Ze6ptxWacjqbBaNQH88NyDFzXGw1rthWnK89_5py9E0WvlRDKKDshes51dQFcQmlF7l3CSchwiREhBqW3Jf7015m3jqpUfz7zRGGhTPwgTRIjWcONJdPvQdHA_ZB2J5xw",
               "width" : 5312
            }
         ],
         "place_id" : "ChIJ_0BrEG4OdkgR5uaXg3OK0as",
         "rating" : 5,
         "reference" : "CmRbAAAA21sx1Zva6COvTQwLmMyFqoOMAbHzoLzlvmRtPxnrVl5wqidhPPM3GqOnxjKAzLKPCX7NByVrKQKFuq4i4Dg02fARzXweEmc-E7HbOXTgqW0yu1PryKZ7vz8Huo1RSLDVEhDv6AWMygbl5GQvow4lSzrzGhRLv-fz2acSLTgRMN47-h4Gvvgb3w",
         "scope" : "GOOGLE",
         "types" : [ "finance", "point_of_interest", "establishment" ],
         "vicinity" : "6 Hay's Ln, London"
      }
   ],
   "status" : "OK"
}

Once you have a place identifier, you can retrieve further information about that place by calling the Google Places API as described here:

https://developers.google.com/places/web-service/details

To retrieve detailed information about Domus Finance Ltd from the Google Places API, you could make the following request (you must substitute your own API key):

https://maps.googleapis.com/maps/api/place/details/json?key=YourAPIKeyGoesHere&placeid=ChIJ_0BrEG4OdkgR5uaXg3OK0as

When the place details URL specified above is executed (either via code or by entering the URL into the address bar of a web browser), JSON is returned that contains information about Domus Finance Ltd:

{
   "html_attributions" : [],
   "result" : {
      "address_components" : [
         {
            "long_name" : "6",
            "short_name" : "6",
            "types" : [ "street_number" ]
         },
         {
            "long_name" : "Hay's Lane",
            "short_name" : "Hay's Ln",
            "types" : [ "route" ]
         },
         {
            "long_name" : "London",
            "short_name" : "London",
            "types" : [ "postal_town" ]
         },
         {
            "long_name" : "Greater London",
            "short_name" : "Greater London",
            "types" : [ "administrative_area_level_2", "political" ]
         },
         {
            "long_name" : "England",
            "short_name" : "England",
            "types" : [ "administrative_area_level_1", "political" ]
         },
         {
            "long_name" : "United Kingdom",
            "short_name" : "GB",
            "types" : [ "country", "political" ]
         },
         {
            "long_name" : "SE1 2HB",
            "short_name" : "SE1 2HB",
            "types" : [ "postal_code" ]
         }
      ],
      "adr_address" : "\u003cspan class=\"street-address\"\u003e6 Hay's Ln\u003c/span\u003e, \u003cspan class=\"locality\"\u003eLondon\u003c/span\u003e \u003cspan class=\"postal-code\"\u003eSE1 2HB\u003c/span\u003e, \u003cspan class=\"country-name\"\u003eUK\u003c/span\u003e",
      "formatted_address" : "6 Hay's Ln, London SE1 2HB, UK",
      "formatted_phone_number" : "020 3393 4333",
      "geometry" : {
         "location" : {
            "lat" : 51.5055825,
            "lng" : -0.0848951
         },
         "viewport" : {
            "northeast" : {
               "lat" : 51.50687668029151,
               "lng" : -0.08345466970849796
            },
            "southwest" : {
               "lat" : 51.50417871970851,
               "lng" : -0.08615263029150204
            }
         }
      },
      "icon" : "https://maps.gstatic.com/mapfiles/place_api/icons/generic_business-71.png",
      "id" : "6ab3107787593d2a6346a82474573c099df3adbb",
      "international_phone_number" : "+44 20 3393 4333",
      "name" : "Domus Finance Ltd",
      "opening_hours" : {
         "open_now" : true,
         "periods" : [
            {
               "close" : {
                  "day" : 1,
                  "time" : "2000"
               },
               "open" : {
                  "day" : 1,
                  "time" : "0800"
               }
            },
            {
               "close" : {
                  "day" : 2,
                  "time" : "2000"
               },
               "open" : {
                  "day" : 2,
                  "time" : "0800"
               }
            },
            {
               "close" : {
                  "day" : 3,
                  "time" : "2000"
               },
               "open" : {
                  "day" : 3,
                  "time" : "0800"
               }
            },
            {
               "close" : {
                  "day" : 4,
                  "time" : "2000"
               },
               "open" : {
                  "day" : 4,
                  "time" : "0800"
               }
            },
            {
               "close" : {
                  "day" : 5,
                  "time" : "2000"
               },
               "open" : {
                  "day" : 5,
                  "time" : "0800"
               }
            },
            {
               "close" : {
                  "day" : 6,
                  "time" : "2000"
               },
               "open" : {
                  "day" : 6,
                  "time" : "0800"
               }
            }
         ],
         "weekday_text" : [
            "Monday: 8:00 AM – 8:00 PM",
            "Tuesday: 8:00 AM – 8:00 PM",
            "Wednesday: 8:00 AM – 8:00 PM",
            "Thursday: 8:00 AM – 8:00 PM",
            "Friday: 8:00 AM – 8:00 PM",
            "Saturday: 8:00 AM – 8:00 PM",
            "Sunday: Closed"
         ]
      },
      "photos" : [
         {
            "height" : 2988,
            "html_attributions" : [
               "\u003ca href=\"https://maps.google.com/maps/contrib/116015202095694665382/photos\"\u003eDomus Finance Ltd\u003c/a\u003e"
            ],
            "photo_reference" : "CmRaAAAA9Ros23brDO2JhFePYztbNRPgvAuJq5YauT5QqGy6i5PtEA8dRQMHCZQ8vBqafvrN5jL-yhRSKE-OTvpOnhRKCxCaHjqKqvggwZORF2s3LCXhCsBEms2AQbKZ6RsyWngmEhCWTPK2TiOQv5uxgsrAZXUcGhS2Xc-A5oSkmJbkQytvSwc5NnLIbw",
            "width" : 5312
         },
         {
            "height" : 2988,
            "html_attributions" : [
               "\u003ca href=\"https://maps.google.com/maps/contrib/116015202095694665382/photos\"\u003eDomus Finance Ltd\u003c/a\u003e"
            ],
            "photo_reference" : "CmRaAAAAXAI4CISeEPgDK4PNMtce_k2hhdyd9uI4x-JjBUAWd_72GTr5_4MS8EbUZZCQI7l0N6MlALgjOfWmufM3k4GxJaDJ0Em4s9PL7iaS8Tr3daU57akm824NB63AdBqc_CA5EhCY2eNC3gHWRLUa7uOHI_ZlGhQXmTqrXu3nQkVlrBMncWn3RmGe5A",
            "width" : 5312
         },
         {
            "height" : 1494,
            "html_attributions" : [
               "\u003ca href=\"https://maps.google.com/maps/contrib/116015202095694665382/photos\"\u003eDomus Finance Ltd\u003c/a\u003e"
            ],
            "photo_reference" : "CmRaAAAAzuaQu7i3opqN6JeqTsfhnvEZQdFeKx5Sz7hJAhd7P5mf--mC5p8CbtHO8EIOiYaD4HqpozG1AXbuqNe6AM4AvDgLTK11Ld9ZH5UQxznxfTZ03xMqT3RA3XQtV1Pg16cDEhAhWwursPwWzC2FF_dp4DjMGhRqQnSK7CQXFaWBa32mHqf_e1hipg",
            "width" : 2656
         },
         {
            "height" : 2988,
            "html_attributions" : [
               "\u003ca href=\"https://maps.google.com/maps/contrib/116015202095694665382/photos\"\u003eDomus Finance Ltd\u003c/a\u003e"
            ],
            "photo_reference" : "CmRaAAAATrt1WIz-Jx6wjQkOUD1w3AXWpJD-6R8WNeeyCfhaPiDo56XvFpTSxB1vKHCExn_plv8YUqSVG0Su3Jw121bXVuCNPJd2OiiKZiMSgDff5zzfCD_qbXUO8nuZ4d07d_EDEhALPagSI0vyJMVDtEg3XyvAGhSO5GH7gFGiZfqzeevf64rIuXDluA",
            "width" : 5312
         },
         {
            "height" : 2656,
            "html_attributions" : [
               "\u003ca href=\"https://maps.google.com/maps/contrib/116015202095694665382/photos\"\u003eDomus Finance Ltd\u003c/a\u003e"
            ],
            "photo_reference" : "CmRaAAAAwEszRKkmMmExY-4gWndrQp1zfrRibAAcS62mv_kZMQecPeoe8NCLx4r1zOnno-OsEShkUj2gkTdSV5Bh2nKOmAyjzDCPAjYSI2PRzqLdAb94fIdmoZ0O5oYJ87yAmJeSEhASe6T6I7gIg0pFiO6gTAWDGhQie6PoorzbMI6C4SNipciqM-_16g",
            "width" : 1494
         },
         {
            "height" : 2656,
            "html_attributions" : [
               "\u003ca href=\"https://maps.google.com/maps/contrib/116015202095694665382/photos\"\u003eDomus Finance Ltd\u003c/a\u003e"
            ],
            "photo_reference" : "CmRaAAAAqeSxMxEs-AFZfDQS7QReYBB0XF7DenXpu-xs8Ya04A7Alw-d8sTOSKrrlzSH_mBCA0zYjt43YpT630UFGMAET1sOy0P8PgtCm8kANdT29XNOiz6FJ1U-OFWygEpuuxHOEhB6Xl2PyEHMNgt5Z0C2VEqcGhRO6ANaaEKMyHYFG7IOcDLt2wFUEw",
            "width" : 1494
         },
         {
            "height" : 1000,
            "html_attributions" : [
               "\u003ca href=\"https://maps.google.com/maps/contrib/116015202095694665382/photos\"\u003eDomus Finance Ltd\u003c/a\u003e"
            ],
            "photo_reference" : "CmRaAAAAWyjICpV8W9rnCkZu58uGPnNB-VG7j-O5vI-bIoCaUqscbvufKSeoSNZv5zbIoD65ve1LrAL0qv9qWJMq0m6wCZ8nlm1wYjnBmSmjH2Co7lNLtNG70EIkia4w_k7f47z3EhANC4JBzodXu390BAYWbyPIGhSk2N7SImiDZCq1gF9mX02p2UBXlg",
            "width" : 1000
         },
         {
            "height" : 1152,
            "html_attributions" : [
               "\u003ca href=\"https://maps.google.com/maps/contrib/116015202095694665382/photos\"\u003eDomus Finance Ltd\u003c/a\u003e"
            ],
            "photo_reference" : "CmRaAAAAHTNY78QcUy2SeDaaLT0DmGZ22lSGIopahhUJKqZs3CzftvOOwaFSGmulZRSxjRS7Xrw9uMRsgPAYr5bZ7t-qD62cLbHJzWefIs6lfbb8F4ZjgaWp_G6IywzYeyHPz8rREhCc9HnzStgnq9htDhVAEz3RGhTbFg1JY7yrYmxibPmdoUD99vGMIQ",
            "width" : 2048
         },
         {
            "height" : 1440,
            "html_attributions" : [
               "\u003ca href=\"https://maps.google.com/maps/contrib/116015202095694665382/photos\"\u003eDomus Finance Ltd\u003c/a\u003e"
            ],
            "photo_reference" : "CmRaAAAAQYs7bz6gPq3mx8vTymzExoqJVMNJ73YHfqII7ZB4GTk2U8PWJa_c2PMwYjwMgkhurDikdvXB-UazZ_HOjpK_ZX8pdtwflXTzNBgfN4dD3wcgMOfyDHXtOEGUPuAkWAD6EhBxPYm0fnM1jit54JATFouVGhRG15REQ41r2IvrmlAY0ejO8DOsgw",
            "width" : 1445
         }
      ],
      "place_id" : "ChIJ_0BrEG4OdkgR5uaXg3OK0as",
      "rating" : 5,
      "reference" : "CmRSAAAAXJLGWK74-cJJcbWW5rrBjQC5jAijXj_Jp1DbqNhA3WnZc-Bpa07njH5T7fudr4R53-_B_jc6qONNnDQPDFSgtXC-fkwMSOvomCMbmJRf-xznacXDntk3J8ROOzYl3qcnEhCI-hhdIjhyHrFyxiNg2lgeGhTD4uunPUFUvVa_UDpymJppPzDqGg",
      "reviews" : [
         {
            "author_name" : "Alexis Student",
            "author_url" : "https://www.google.com/maps/contrib/105323533219575917091/reviews",
            "language" : "en",
            "profile_photo_url" : "https://lh3.googleusercontent.com/-uYeNv1bJ6Cw/AAAAAAAAAAI/AAAAAAAAACM/qB8mBPhSyYE/s128-c0x00000000-cc-rp-mo/photo.jpg",
            "rating" : 5,
            "relative_time_description" : "2 months ago",
            "text" : "What a great service we were given on two separate mortgage applications. On both occasions we finished the process happy and confident that we received a great deal on our mortgage. The team at Domus Finance provides excellent impartial information about the various products available on the market, which made it super easy to pick the product of our choice. I work long hours and I don't have time to shop around for mortgages. They made the process so easy and seamless that I would never consider an alternative again. I referred my good friend to this company, and he was very grateful for the introduction. You need to understand the market to get a good rate, not just what one bank offers. I think going direct to your bank would put you in a vulnerable position, they could (and probably would) charge you a premium, and you wouldn't know any different. At least you know with Domus Finance you are getting honest and transparent advice, which in this day in age, is worth its weight in gold.",
            "time" : 1510446711
         },
         {
            "author_name" : "Tim Rogers",
            "author_url" : "https://www.google.com/maps/contrib/103455434500431448503/reviews",
            "language" : "en",
            "profile_photo_url" : "https://lh4.googleusercontent.com/-twRL1tXCOYQ/AAAAAAAAAAI/AAAAAAAAAAA/x9FA_39hZLM/s128-c0x00000000-cc-rp-mo/photo.jpg",
            "rating" : 5,
            "relative_time_description" : "a month ago",
            "text" : "We have used Domus Finance several times for our mortgage and each time Rob and the team have provided an excellent service, answering all of our questions swiftly and ensuring that we get the best possible deal. Highly recommended, we wouldn't go anywhere else.",
            "time" : 1515161771
         },
         {
            "author_name" : "James Gray",
            "author_url" : "https://www.google.com/maps/contrib/107102079830691423058/reviews",
            "language" : "en",
            "profile_photo_url" : "https://lh5.googleusercontent.com/-GEVdAdkjYW8/AAAAAAAAAAI/AAAAAAAAAAA/ACSILjXaNw8GjX8lH39uAh0anat_4wRTBw/s128-c0x00000000-cc-rp-mo/photo.jpg",
            "rating" : 5,
            "relative_time_description" : "5 months ago",
            "text" : "We were recommended to Domus Finance through a friend. We were so happy with the advice given to us by Rob and his team, and were amazed at the level of service we were provided. The team there are extremely knowledgeable and helped us to purchase our first home, which we are very pleased with! We have recommended them to everyone we know and we will definitely be using them again in the future.",
            "time" : 1504122207
         },
         {
            "author_name" : "Robert Stephens",
            "author_url" : "https://www.google.com/maps/contrib/103130438279007083594/reviews",
            "language" : "en",
            "profile_photo_url" : "https://lh6.googleusercontent.com/-ULgCaWR69Lo/AAAAAAAAAAI/AAAAAAAAAAA/ACSILjVO8iZtU4lK1QUrmWV2V-4a6m5mnA/s128-c0x00000000-cc-rp-mo/photo.jpg",
            "rating" : 5,
            "relative_time_description" : "5 months ago",
            "text" : "We're used Domus there times now- over 6 years. Rob and his team at Domus finance are fabulous- he even manages to make mortgages sound interesting!!  Seriously though- top service, quick, great attention to detail always happy to talk through the options whether you're first time, re-mortgaging, restructuring the mortgage etc ***** recommendation!",
            "time" : 1502535044
         },
         {
            "author_name" : "Oliver Campion",
            "author_url" : "https://www.google.com/maps/contrib/108422641230519657837/reviews",
            "language" : "en",
            "profile_photo_url" : "https://lh4.googleusercontent.com/-nBTxyM7TqL0/AAAAAAAAAAI/AAAAAAAAABk/z1moBnWzAto/s128-c0x00000000-cc-rp-mo-ba3/photo.jpg",
            "rating" : 5,
            "relative_time_description" : "10 months ago",
            "text" : "Rob Still is professional, knowledgeable and friendly. We had a lot of false starts when trying to buy but Rob helped at every turn and his services were worth every penny. I cannot understate how much effort and personal attention Rob gives. As stressful as buying my first home has been, I am glad I didn't have to worry about the financing as well, and I'm confident Rob's efforts got me the best deal. I would come back to him if I find myself looking at buying again.",
            "time" : 1490645507
         }
      ],
      "scope" : "GOOGLE",
      "types" : [ "finance", "point_of_interest", "establishment" ],
      "url" : "https://maps.google.com/?cid=12380829079351846630",
      "utc_offset" : 0,
      "vicinity" : "6 Hay's Lane, London",
      "website" : "http://www.domusfinance.co.uk/"
   },
   "status" : "OK"
}

Hopefully this article has shown you how easy it is to get up and running with the Google Places API. If you have any questions or comments, please leave them in the forum below.