Categories: softare development

How to Use Google Places AutoComplete in React Native

The Google Places Autocomplete feature in mobile software development is useful for searching for verified locations that are available on Google Maps.

In this tutorial, we are going to see how we can use the Google Places Autocomplete feature in our React Native application.

Let’s get started!

1. Obtain an API key from Google Cloud Console

First you need to add billing to your Google Cloud Console account and enable Geocoding.

2. Install the Google Places AutoComplete dependency

Read more about the Google AutoComplete dependency

yarn add react-native-google-places-autocomplete

3. Add code for the Google API

<GooglePlacesAutocomplete
    placeholder='Search location'
    returnKeyType={'default'}
    fetchDetails={true}
    currentLocation = {true}
    isRowScrollable={true}
    keepResultsAfterBlur={false}
    enablePoweredByContainer = { false }
    styles={{
      textInputContainer: {
        marginTop: 0,
      },
      textInput: {
        height: 45,
        color: 'black',
        fontSize: 16,
        backgroundColor: '#ddd'
      },
      predefinedPlacesDescription: {
        color: '#1faadb',
      },
      listView: {
        position: 'relative',
        zIndex: 3,
        marginTop: 0,
        padding: 0
      },
      row: {
      backgroundColor: '#FFFFFF',
      height: 100,
      flexDirection: 'row',
      },
      separator: {
      height: 0.5,
      backgroundColor: '#c8c7cc',
      },
      description: {},
      loader: {
      flexDirection: 'row',
      justifyContent: 'flex-end',
      height: 20,
      },
    }}

    onPress={(data, details) => {
      // 'details' is provided when fetchDetails = true
      // console.warn(details);
    }}
    query={{
      key: API_KEY,
      language: 'en',
      components: 'country:us'
    }}
    />

Result:

Did it work out for you? Let me know in the comments.

Don’t build mobile apps from scratch

Recent Posts

Service Workers in JavaScript: An In-Depth Guide

Service Workers are one of the core features of modern web applications, offering powerful capabilities…

1 week ago

What are Database Driven Websites?

A database-driven website is a dynamic site that utilizes a database to store and manage…

2 weeks ago

How to show Toast Messages in React

Toasts are user interface elements commonly used in software applications, especially in mobile app development…

2 weeks ago

Exploring the Relationship Between JavaScript and Node.js

JavaScript has long been synonymous with frontend web development, powering interactive and dynamic user interfaces…

3 weeks ago

Key Differences Between Tailwind CSS and CSS3

Introduction: In the world of web development, CSS (Cascading Style Sheets) plays a crucial role…

3 weeks ago

Why Everybody is Learning JavaScript Right Now

JavaScript has emerged as a ubiquitous programming language, powering the modern web and extending its…

3 weeks ago