react-google-autocomplete

React component for google autocomplete.

React google autocomplete

This is a simple react component for working with google autocomplete

Install

npm i react-google-autocomplete --save

You also have to include google autocomplete link api in your app. Somewhere in index.html or somwhere else.

  <script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=[YOUR_API_KEY]&libraries=places"></script>

Example

import Autocomplete from 'react-google-autocomplete';

<Autocomplete
    style={{width: '90%'}}
    onPlaceSelected={(place) => {
      console.log(place);
    }}
    types={['(regions)']}
    componentRestrictions={{country: "ru"}}
/>

The component has one function called onPlaceSelected. The function gets invoked every time a user chooses location.
A types props means type of places in google place API. By default it uses (cities).
A componentRestrictions prop by default is empty.
A bounds prop by default is empty.
You also can pass any props you want to the final input. You can also set fields prop if you need extra information, now it defaults to basic data in order to control expenses.

Contribution

If you would like to see something in this library please create an issue and I will implement it as soon as possible.

主要指标

概览
名称与所有者ErrorPro/react-google-autocomplete
主编程语言JavaScript
编程语言JavaScript (语言数: 1)
平台
许可证MIT License
所有者活动
创建于2016-05-21 11:31:32
推送于2025-04-03 13:20:08
最后一次提交2025-04-03 15:17:37
发布数16
最新版本名称v2.6.1 (发布于 )
第一版名称v2.0.0 (发布于 )
用户参与
星数496
关注者数7
派生数120
提交数123
已启用问题?
问题数197
打开的问题数46
拉请求数43
打开的拉请求数2
关闭的拉请求数9
项目设置
已启用Wiki?
已存档?
是复刻?
已锁定?
是镜像?
是私有?