Source:  Twitter logo

I am trying to get Google Places (autocomplete field) integrated with my reactjs website styled with Material UI. I did find this demo on Material UI documentation Google Maps place but It didn't work for me when I did change on the input nothing change

demo :

thank you hope you get what I'm trying to explain

If you take a look on the Console of that demo you'll see the error:

Google Maps JavaScript API error: InvalidKeyMapError

Google Maps only works with valid API keys, the one provided by default on that demo is invalid for security purposes, you have to generate your own, it can be done here:

1 users liked answer #0dislike answer #01
yuri profile pic

Helo, try this code bellow:

// Imports
import React, { Component } from 'react';

// Import Search Bar Components
import SearchBar from 'material-ui-search-bar';

// Import React Scrit Libraray to load Google object
import Script from 'react-load-script';

class Search extends Component {
  // Define Constructor
  constructor(props) {

    // Declare State
    this.state = {
      city: '',
      query: ''


  handleScriptLoad = () => {
    // Declare Options For Autocomplete
    const options = {
      types: ['(cities)'],

    // Initialize Google Autocomplete
    /*global google*/ // To disable any eslint 'google not defined' errors
    this.autocomplete = new google.maps.places.Autocomplete(

    // Avoid paying for data that you don't need by restricting the set of
    // place fields that are returned to just the address components and formatted
    // address.
    this.autocomplete.setFields(['address_components', 'formatted_address']);

    // Fire Event when a suggested name is selected
    this.autocomplete.addListener('place_changed', this.handlePlaceSelect);

  handlePlaceSelect = () => {

    // Extract City From Address Object
    const addressObject = this.autocomplete.getPlace();
    const address = addressObject.address_components;

    // Check if address is valid
    if (address) {
      // Set State
          city: address[0].long_name,
          query: addressObject.formatted_address,

  render() {
    return (
        <SearchBar id="autocomplete" placeholder="" hintText="Search City" value={this.state.query}
            margin: '0 auto',
            maxWidth: 800,

export default Search;

if you have some doubt, please follow the link:

0 users liked answer #1dislike answer #10
Matheus cabral profile pic
Matheus cabral

I did forget to install lodash it's working fine now


-1 users liked answer #2dislike answer #2-1
Buk Lau profile pic
Buk Lau

Copyright © 2022 QueryThreads

All content on Query Threads is licensed under the Creative Commons Attribution-ShareAlike 3.0 license (CC BY-SA 3.0).