Google Places Extension



Have you ever needed to get a user to select a place in your app? Well now you can achieve this using the Google Places API, I have developed an extension to make it easier to get started using Google Places in your app.

The Google Places API has a couple different endpoint that can be used as follows:

  • PlacesAutocomplete API - As a user types into a search box you can automatically use this to load suggestions
  • PlaceDetails API - Returns detail information about the particular business or location the user has selected
  • PlaceSearch API - Enables you to search for a business or location based on a users location or specified latitude and longitude coordinates
× This extension returns a response from the Google Places API in JSON format, I recommend that you use our JSON Tools Extension to more easily integrate with this extension.

Extension Usage

SetAPIKey

To start using the extension you will need to provide your Google Places API Key, if you don't already have one you can create a free API key following the instructions at the following url.


Start/Stop Autocomplete Session


If you are using the autocomplete API, you may use the StartAutocompleteSession block to generate a unique identifier for the session, and once a user has selected a place you may use the StopAutocompleteSession to clear the session. The unique identifier is used for Google Cloud billing purposes and if not used, each request will be billed individually as per the Google Places documentation.
Read more about this at the Google Places docs.



Methods

ExecutePlaceSearchRequest


Place Search finds places near the given coordinates within the given radius and returns JSON output which includes basic information such as place name, price level, and whether the place is currently open. In this method lat, lng, and radius are required, type and name are optional and can be set to an empty String if not required.

To see additional attributes you can use with this method using the "SetAdditionalAttributes" block, refer to the Google Places documentation here: Places API - Place Search

ExecutePlaceDetailsRequest


Place Details is a method to get further information on a place. Place details takes a placeid as a parameter which can be obtained from your place search request.

To see additional attributes you can use with this method using the "SetAdditionalAttributes" block, refer to the Google Places documentation here: Places API - Place Details

ExecutePlaceAutocompleteRequest

Autocomplete is a method to get suggestions based on text the user has entered into an input field. input is a required parameter and contains the user entered text. types is an optional parameter and allows you to filter results by a range of different types. for further information refer to Google's documentation: Place API - Place Autocomplete

You can find a complete list of the different place types in Googles Documentation here: Place API - Supported Types

To see additional attributes you can use with this method using the "SetAdditionalAttributes" block, refer to the Google Places documentation here: Places API - Autocomplete

SetAdditionalAttributes

This method allows you to set additional optional attributes which are not covered in the function declarations. One example might be language, by using this method you could change the language as well as many other attributes. This variable is cleared automatically after each request. Ensure attributes you specify are in the correct format, start the attributes with ampersand not a question mark e.g. &language=en-AU&minprice=3

GetPhotoURL

This gets the URL for a photo using the photo_reference in the Place Details JSON response. Note your API key is in the returned URL, will look at ways to improve this in a future release, however you can also restrict access to your API key in Google Cloud Console.


Example

The following example project allows you to search for a business and display the details for the business, including getting photos of the business, ratings, open hours, and more.

To test this for yourself just download the .aia file, enter your API Key in the code, and export your app.





Download Google Places Extension


Download the example project: GooglePlacesExampleCode.aia

Download the Google Places extension: GooglePlacesExtension.aix



Mind the Terms and Conditions

Be sure to review the T&Cs from the Google Places API before you implement it, here's just a couple highlights from the Google Places documentation.


 



Version History

Version 1

Initial release with the following methods:

-StartAutocompleteSession
-StopAutocompleteSession
-GetPhotoURL
-SetAdditionalAttributes
-SetAPIKey
-ExecutePlaceSearchRequest
-ExecutePlaceDetailsRequest
-ExecutePlaceAutocompleteRequest



Icons made by surang from www.flaticon.com

Was this helpful?

Yes No

Comments

  1. Hello do you have a YouTube video?

    ReplyDelete
    Replies
    1. I hope to do some videos in the future but I do have the demo app you can download and explore.

      Delete
  2. Hi Can we use your Extension in MIT App Hackathon 2020??

    ReplyDelete
    Replies
    1. Hi HM,

      Absolutely you can, would love to see what you make with it 😀

      Delete

Post a Comment

Thunkable Components