{"id":281,"date":"2022-01-17T17:07:24","date_gmt":"2022-01-17T17:07:24","guid":{"rendered":"https:\/\/blog.staginginstance.com\/?p=281"},"modified":"2022-01-18T17:46:30","modified_gmt":"2022-01-18T17:46:30","slug":"how-to-use-google-places-api","status":"publish","type":"post","link":"https:\/\/geekabhi.com\/blog\/how-to-use-google-places-api\/","title":{"rendered":"How to use Google places API"},"content":{"rendered":"\n<p>Google places API is a highly valuable resource if you&#8217;re looking for certain types of places in a certain region (eg. an Indian restaurant in New York), identifying a business, generating leads for a list of professionals (eg electricians, plumbers, etc). <\/p>\n\n\n\n<p>By Google definition, the Places API is a service that returns information about places using HTTP requests. Places are defined within this API as establishments, geographic locations, or prominent points of interest.<\/p>\n\n\n\n<p>Google has moved everything related to geolocation, places, maps under a hood named &#8220;Google Maps Platform&#8221;, and is not free anymore. Over the years, it was free until Google realized the potential of these services and now requires you to set up a billing account before you can actually use it. Though they do provide a $200 credit, you still need to put in a card.<\/p>\n\n\n\n<p>So to get started:<\/p>\n\n\n\n<ol><li>create an account at <a href=\"https:\/\/mapsplatform.google.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">Google&#8217;s Cloud Platform<\/a> with billing. <\/li><li>Once set up, please go to the <a href=\"https:\/\/console.cloud.google.com\/google\/maps-apis\/start\" target=\"_blank\" rel=\"noreferrer noopener\">API Console<\/a>, and create a project.<\/li><li>Once our project is created, we can actually decide which apis we want to use and enable only those. This is important as we don&#8217;t want to enable the apis we won&#8217;t use as if the API keys ever gets compromised, the key will only limit to certain API only and not to the whole API collection. This is how it will look once APIs are enabled. <img decoding=\"async\" loading=\"lazy\" width=\"1591\" height=\"803\" class=\"wp-image-282\" style=\"width: 600px;\" src=\"https:\/\/blog.staginginstance.com\/wp-content\/uploads\/2022\/01\/googleAPIs.png\" alt=\"\" srcset=\"https:\/\/geekabhi.com\/blog\/wp-content\/uploads\/2022\/01\/googleAPIs.png 1591w, https:\/\/geekabhi.com\/blog\/wp-content\/uploads\/2022\/01\/googleAPIs-300x151.png 300w, https:\/\/geekabhi.com\/blog\/wp-content\/uploads\/2022\/01\/googleAPIs-1024x517.png 1024w, https:\/\/geekabhi.com\/blog\/wp-content\/uploads\/2022\/01\/googleAPIs-768x388.png 768w, https:\/\/geekabhi.com\/blog\/wp-content\/uploads\/2022\/01\/googleAPIs-1536x775.png 1536w, https:\/\/geekabhi.com\/blog\/wp-content\/uploads\/2022\/01\/googleAPIs-1568x791.png 1568w\" sizes=\"(max-width: 1591px) 100vw, 1591px\" \/><\/li><li>Now, we have the APIs we want to use, we can start using them. You can find all the documentation here: https:\/\/developers.google.com\/maps\/documentation. We will be using places API in this article, but you can use whichever API you want based on your requirement.<\/li><li>Before we go further into API development, we need to generate API keys. To create keys, go to: <a href=\"https:\/\/console.cloud.google.com\/google\/maps-apis\/credentials\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/console.cloud.google.com\/google\/maps-apis\/credentials<\/a> and click &#8220;Create Credentials&#8221; button. It will create an API key for you and will ask you to restrict the API key. Click &#8220;Restrict key&#8221; to go to the restrictions settings page. Choose the appropriate restrictions based on the app you will be integrating API with.<\/li><li>Now to use API we can either select and SDK (JS, IOS, ) or just simply use HTTP API calls from the language of your choice.<\/li><li>Here are the list of place requests types available on Google to query places and its metadata:<ul><li><a href=\"https:\/\/developers.google.com\/maps\/documentation\/places\/web-service\/search\" target=\"_blank\" rel=\"noreferrer noopener\">Place Search<\/a>\u00a0returns a list of places based on a user&#8217;s location or search string.<\/li><li><a href=\"https:\/\/developers.google.com\/maps\/documentation\/places\/web-service\/details\" target=\"_blank\" rel=\"noreferrer noopener\">Place Details<\/a>\u00a0returns more detailed information about a specific place, including user reviews.<\/li><li><a href=\"https:\/\/developers.google.com\/maps\/documentation\/places\/web-service\/photos\" target=\"_blank\" rel=\"noreferrer noopener\">Place Photos<\/a>\u00a0provides access to the millions of place-related photos stored in Google&#8217;s Place database.<\/li><li><a href=\"https:\/\/developers.google.com\/maps\/documentation\/places\/web-service\/autocomplete\" target=\"_blank\" rel=\"noreferrer noopener\">Place Autocomplete<\/a>\u00a0automatically fills in the name and\/or address of a place as users type.<\/li><li><a href=\"https:\/\/developers.google.com\/maps\/documentation\/places\/web-service\/query\" target=\"_blank\" rel=\"noreferrer noopener\">Query Autocomplete<\/a>\u00a0provides a query prediction service for text-based geographic searches, returning suggested queries as users type.<\/li><\/ul><\/li><li>To do a place search, we need to use Place Search. There are three search endpoints available with different characteristics with Place Search. The following table highlights some of these differences (taken from <a href=\"https:\/\/developers.google.com\/maps\/documentation\/places\/web-service\/search\" target=\"_blank\" rel=\"noreferrer noopener\">Google<\/a>): <img decoding=\"async\" loading=\"lazy\" width=\"1170\" height=\"418\" class=\"wp-image-283\" style=\"width: 600px;\" src=\"https:\/\/blog.staginginstance.com\/wp-content\/uploads\/2022\/01\/Place-Search-_-Places-API-_-Google-Developers.png\" alt=\"\" srcset=\"https:\/\/geekabhi.com\/blog\/wp-content\/uploads\/2022\/01\/Place-Search-_-Places-API-_-Google-Developers.png 1170w, https:\/\/geekabhi.com\/blog\/wp-content\/uploads\/2022\/01\/Place-Search-_-Places-API-_-Google-Developers-300x107.png 300w, https:\/\/geekabhi.com\/blog\/wp-content\/uploads\/2022\/01\/Place-Search-_-Places-API-_-Google-Developers-1024x366.png 1024w, https:\/\/geekabhi.com\/blog\/wp-content\/uploads\/2022\/01\/Place-Search-_-Places-API-_-Google-Developers-768x274.png 768w\" sizes=\"(max-width: 1170px) 100vw, 1170px\" \/><\/li><li>Using Find Place, we can do a free search like &#8220;Restaurants in New York&#8221; or &#8220;Hospitals near by&#8221; etc. Here is the API call to the same: <a href=\"https:\/\/maps.googleapis.com\/maps\/api\/place\/findplacefromtext\/json\u00a0 ?fields=formatted_address%2Cname%2Crating%2Copening_hours%2Cgeometry\u00a0 &amp;input=Museum%20of%20Contemporary%20Art%20Australia\u00a0 &amp;inputtype=textquery\u00a0 &amp;key=YOUR_API_KEY\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/maps.googleapis.com\/maps\/api\/place\/findplacefromtext\/json?fields=formatted_address%2Cname%2Crating%2Copening_hours%2Cgeometry&amp;input=Museum%20of%20Contemporary%20Art%20Australia&amp;inputtype=textquery&amp;key=YOUR_API_KEY<\/a><\/li><li>Fields are divided into three billing categories: Basic, Contact, and Atmosphere. Basic fields are billed at base rate, and incur no additional charges. Contact and Atmosphere fields are billed at a higher rate. See the pricing sheet for more information. Attributions, html_attributions, are always returned with every call, regardless of whether the field has been requested. You can read more about them here in detail here: <a href=\"https:\/\/developers.google.com\/maps\/documentation\/places\/web-service\/search-find-place\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/developers.google.com\/maps\/documentation\/places\/web-service\/search-find-place<\/a><\/li><li>Using PHP with Curl you can do this:<\/li><\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?php\n\n$curl = curl_init();\n\ncurl_setopt_array($curl, array(\n  CURLOPT_URL =&gt; 'https:\/\/maps.googleapis.com\/maps\/api\/place\/findplacefromtext\/json?fields=formatted_address%2Cname%2Crating%2Copening_hours%2Cgeometry&amp;input=Museum%20of%20Contemporary%20Art%20Australia&amp;inputtype=textquery&amp;key=YOUR_API_KEY',\n  CURLOPT_RETURNTRANSFER =&gt; true,\n  CURLOPT_ENCODING =&gt; '',\n  CURLOPT_MAXREDIRS =&gt; 10,\n  CURLOPT_TIMEOUT =&gt; 0,\n  CURLOPT_FOLLOWLOCATION =&gt; true,\n  CURLOPT_HTTP_VERSION =&gt; CURL_HTTP_VERSION_1_1,\n  CURLOPT_CUSTOMREQUEST =&gt; 'GET',\n));\n\n$response = curl_exec($curl);\n\ncurl_close($curl);\necho $response;<\/code><\/pre>\n\n\n\n<p>Hope this helps.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Google places API is a highly valuable resource if you&#8217;re looking for certain types of places in a certain region (eg. an Indian restaurant in New York), identifying a business, generating leads for a list of professionals (eg electricians, plumbers, etc). By Google definition, the Places API is a service that returns information about places&hellip; <a class=\"more-link\" href=\"https:\/\/geekabhi.com\/blog\/how-to-use-google-places-api\/\">Continue reading <span class=\"screen-reader-text\">How to use Google places API<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to use Google places API - Learner at life<\/title>\n<meta name=\"description\" content=\"Google places API is a highly valuable resource if you&#039;re looking for certain types of places in a certain region (eg. an Indian restaurant in New York), identifying a business, generating leads for a list of professionals (eg electricians, plumbers, etc).\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/geekabhi.com\/blog\/how-to-use-google-places-api\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to use Google places API\" \/>\n<meta property=\"og:description\" content=\"Google places API is a highly valuable resource if you&#039;re looking for certain types of places in a certain region (eg. an Indian restaurant in New York), identifying a business, generating leads for a list of professionals (eg electricians, plumbers, etc).\" \/>\n<meta property=\"og:url\" content=\"https:\/\/geekabhi.com\/blog\/how-to-use-google-places-api\/\" \/>\n<meta property=\"og:site_name\" content=\"Learner at life\" \/>\n<meta property=\"article:publisher\" content=\"http:\/\/abhij89\" \/>\n<meta property=\"article:published_time\" content=\"2022-01-17T17:07:24+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-01-18T17:46:30+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/geekabhi.com\/blog\/wp-content\/uploads\/2022\/01\/Place-Search-_-Places-API-_-Google-Developers.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1170\" \/>\n\t<meta property=\"og:image:height\" content=\"418\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Abhishek Jain\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:title\" content=\"How to use Google places API\" \/>\n<meta name=\"twitter:description\" content=\"Google places API is a highly valuable resource if you&#039;re looking for certain types of places in a certain region (eg. an Indian restaurant in New York), identifying a business, generating leads for a list of professionals (eg electricians, plumbers, etc).\" \/>\n<meta name=\"twitter:image\" content=\"https:\/\/geekabhi.com\/blog\/wp-content\/uploads\/2022\/01\/Place-Search-_-Places-API-_-Google-Developers.png\" \/>\n<meta name=\"twitter:creator\" content=\"@abhij89\" \/>\n<meta name=\"twitter:site\" content=\"@abhij89\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Abhishek Jain\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/geekabhi.com\/blog\/how-to-use-google-places-api\/\",\"url\":\"https:\/\/geekabhi.com\/blog\/how-to-use-google-places-api\/\",\"name\":\"How to use Google places API - Learner at life\",\"isPartOf\":{\"@id\":\"https:\/\/geekabhi.com\/blog\/#website\"},\"datePublished\":\"2022-01-17T17:07:24+00:00\",\"dateModified\":\"2022-01-18T17:46:30+00:00\",\"author\":{\"@id\":\"https:\/\/geekabhi.com\/blog\/#\/schema\/person\/75cf5ee8cc7d8c1a9ba81628bb57443e\"},\"description\":\"Google places API is a highly valuable resource if you're looking for certain types of places in a certain region (eg. an Indian restaurant in New York), identifying a business, generating leads for a list of professionals (eg electricians, plumbers, etc).\",\"breadcrumb\":{\"@id\":\"https:\/\/geekabhi.com\/blog\/how-to-use-google-places-api\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/geekabhi.com\/blog\/how-to-use-google-places-api\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/geekabhi.com\/blog\/how-to-use-google-places-api\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/geekabhi.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to use Google places API\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/geekabhi.com\/blog\/#website\",\"url\":\"https:\/\/geekabhi.com\/blog\/\",\"name\":\"Learner at life\",\"description\":\"Blog to help you learn stuff\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/geekabhi.com\/blog\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/geekabhi.com\/blog\/#\/schema\/person\/75cf5ee8cc7d8c1a9ba81628bb57443e\",\"name\":\"Abhishek Jain\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/geekabhi.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/85387a40fe2c6954082743d1a8aa6c0f?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/85387a40fe2c6954082743d1a8aa6c0f?s=96&d=mm&r=g\",\"caption\":\"Abhishek Jain\"},\"description\":\"Techie with 10+ years of experience and counting.\",\"sameAs\":[\"http:\/\/www.geekabhi.com\",\"https:\/\/twitter.com\/abhij89\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to use Google places API - Learner at life","description":"Google places API is a highly valuable resource if you're looking for certain types of places in a certain region (eg. an Indian restaurant in New York), identifying a business, generating leads for a list of professionals (eg electricians, plumbers, etc).","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/geekabhi.com\/blog\/how-to-use-google-places-api\/","og_locale":"en_US","og_type":"article","og_title":"How to use Google places API","og_description":"Google places API is a highly valuable resource if you're looking for certain types of places in a certain region (eg. an Indian restaurant in New York), identifying a business, generating leads for a list of professionals (eg electricians, plumbers, etc).","og_url":"https:\/\/geekabhi.com\/blog\/how-to-use-google-places-api\/","og_site_name":"Learner at life","article_publisher":"http:\/\/abhij89","article_published_time":"2022-01-17T17:07:24+00:00","article_modified_time":"2022-01-18T17:46:30+00:00","og_image":[{"width":1170,"height":418,"url":"https:\/\/geekabhi.com\/blog\/wp-content\/uploads\/2022\/01\/Place-Search-_-Places-API-_-Google-Developers.png","type":"image\/png"}],"author":"Abhishek Jain","twitter_card":"summary_large_image","twitter_title":"How to use Google places API","twitter_description":"Google places API is a highly valuable resource if you're looking for certain types of places in a certain region (eg. an Indian restaurant in New York), identifying a business, generating leads for a list of professionals (eg electricians, plumbers, etc).","twitter_image":"https:\/\/geekabhi.com\/blog\/wp-content\/uploads\/2022\/01\/Place-Search-_-Places-API-_-Google-Developers.png","twitter_creator":"@abhij89","twitter_site":"@abhij89","twitter_misc":{"Written by":"Abhishek Jain","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/geekabhi.com\/blog\/how-to-use-google-places-api\/","url":"https:\/\/geekabhi.com\/blog\/how-to-use-google-places-api\/","name":"How to use Google places API - Learner at life","isPartOf":{"@id":"https:\/\/geekabhi.com\/blog\/#website"},"datePublished":"2022-01-17T17:07:24+00:00","dateModified":"2022-01-18T17:46:30+00:00","author":{"@id":"https:\/\/geekabhi.com\/blog\/#\/schema\/person\/75cf5ee8cc7d8c1a9ba81628bb57443e"},"description":"Google places API is a highly valuable resource if you're looking for certain types of places in a certain region (eg. an Indian restaurant in New York), identifying a business, generating leads for a list of professionals (eg electricians, plumbers, etc).","breadcrumb":{"@id":"https:\/\/geekabhi.com\/blog\/how-to-use-google-places-api\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/geekabhi.com\/blog\/how-to-use-google-places-api\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/geekabhi.com\/blog\/how-to-use-google-places-api\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/geekabhi.com\/blog\/"},{"@type":"ListItem","position":2,"name":"How to use Google places API"}]},{"@type":"WebSite","@id":"https:\/\/geekabhi.com\/blog\/#website","url":"https:\/\/geekabhi.com\/blog\/","name":"Learner at life","description":"Blog to help you learn stuff","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/geekabhi.com\/blog\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/geekabhi.com\/blog\/#\/schema\/person\/75cf5ee8cc7d8c1a9ba81628bb57443e","name":"Abhishek Jain","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/geekabhi.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/85387a40fe2c6954082743d1a8aa6c0f?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/85387a40fe2c6954082743d1a8aa6c0f?s=96&d=mm&r=g","caption":"Abhishek Jain"},"description":"Techie with 10+ years of experience and counting.","sameAs":["http:\/\/www.geekabhi.com","https:\/\/twitter.com\/abhij89"]}]}},"_links":{"self":[{"href":"https:\/\/geekabhi.com\/blog\/wp-json\/wp\/v2\/posts\/281"}],"collection":[{"href":"https:\/\/geekabhi.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/geekabhi.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/geekabhi.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/geekabhi.com\/blog\/wp-json\/wp\/v2\/comments?post=281"}],"version-history":[{"count":3,"href":"https:\/\/geekabhi.com\/blog\/wp-json\/wp\/v2\/posts\/281\/revisions"}],"predecessor-version":[{"id":287,"href":"https:\/\/geekabhi.com\/blog\/wp-json\/wp\/v2\/posts\/281\/revisions\/287"}],"wp:attachment":[{"href":"https:\/\/geekabhi.com\/blog\/wp-json\/wp\/v2\/media?parent=281"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/geekabhi.com\/blog\/wp-json\/wp\/v2\/categories?post=281"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/geekabhi.com\/blog\/wp-json\/wp\/v2\/tags?post=281"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}