🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
DemoInstallSign in
Socket

react-native-places-input

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-native-places-input

Up to date working Google Places Input. Calling directly API not JS SDK.

1.0.10
Source
npm
Version published
Weekly downloads
255
-5.56%
Maintainers
1
Weekly downloads
 
Created
Source

React Native Places Input

Up to date working Google Places Input. Calling directly API not JS SDK.

exmaples

Latest changes

1.0.10

New configuration props:

  • queryTypes - You may restrict results from a Place Autocomplete request to be of a certain type by passing a types parameter.

1.0.9

Fixing an issue with sometimes not getting details about selected place.

1.0.8

Fixed issue that in some cases list of places is not displayed.

New configuration props:

  • requiredCharactersBeforeSearch - component wont fetch places unless string length is equal this prop. Default 2.
  • requiredTimeBeforeSearch - idle time on text input before component will fetch places.

1.0.5

Remove default props for lat,lng and radius. Add queryCountries where you can pass array of countries to limit your search results.

Installation

yarn add react-native-places-input

or

npm install react-native-places-input

Usage

Fairly easy. Few required props but most of the work is already done in a component.

Basic

import PlacesInput from 'react-native-places-input';

And inside a component

    <PlacesInput
        googleApiKey={GOOGLE_API_KEY}
        onSelect={place => console.log(place}
    />
class InputWrapper extends React.Component {
    render() {
        return (
            <View style={{ width: '100%' }}>
                <PlacesInput
                    googleApiKey={GOOGLE_API_KEY}
                    placeHolder={"Some Place holder"}
                    language={"en-US"}
                    onSelect={place => {
                        this.props.goToPoint(get(place, 'result.geometry.location.lat'), get(place, 'result.geometry.location.lng'))
                    }}
                    iconResult={<Ionicons name="md-pin" size={25} style={styles.placeIcon}/>}
                />
            </View>
        );
    }
}

Configuration props

List of props supported by a component

PropTypeDefaultDescription
googleApiKeyPropTypes.string.isRequired,Google API key
iconInputPropTypes.any,Icon added to an input
iconResultPropTypes.any,Icon added to results
languagePropTypes.string,enLanguage for google API call
placeHolderPropTypes.string,Search places...placeholder for an input
queryTypesPropTypes.string,You may restrict results from a Place Autocomplete request to be of a certain type by passing a types parameter. Google docs
queryFieldsPropTypes.string,formatted_address,geometry,nameFields requested from Google API
queryCountriesPropTypes.arrayArray of country codes to limit results
resultRenderPropTypes.func,place => place.descriptionFunction to render results text
searchLatitudePropTypes.number,Lat to limit results
searchLongitudePropTypes.number,Lng to limit results
searchRadiusPropTypes.number,radius to limit results
stylesContainerPropTypes.object,{}Custom styles for a container
stylesInputPropTypes.object,{}Custom styles for an input
stylesItemPropTypes.object,{}Custom styles for an item
stylesItemTextPropTypes.object,{}Custom styles for an item text
stylesListPropTypes.object,{}Custom styles for a list
stylesLoadingPropTypes.object,{}Custom styles for a loading indicator
textInputPropsPropTypes.object,{}Custom TextInput props
requiredCharactersBeforeSearchPropTypes.number2Component wont fetch places unless string length is equal this prop
requiredTimeBeforeSearchPropTypes.number1000Idle time on text input before component will fetch places
onSelectPropTypes.func,Function called when you select a place

Examples

Inline

exmaples

    <PlacesInput
        placeHolder={'Some placeholder'}
        stylesContainer={{
            position: 'relative',
            alignSelf: 'stretch',
            margin: 0,
            top: 0,
            left: 0,
            right: 0,
            bottom: 0,
            shadowOpacity: 0,
            borderColor: '#dedede',
            borderWidth: 1,
            marginBottom: 10
        }}
        stylesList={{
            top: 50,
            borderColor: '#dedede',
            borderLeftWidth: 1,
            borderRightWidth: 1,
            borderBottomWidth: 1,
            left: -1,
            right: -1
        }}
        googleApiKey={GOOGLE_API_KEY} 
        onSelect={place => this.setState({place})} 
    />

Limit results to a country

    <PlacesInput
        placeHolder={'Some placeholder'}
        queryCountries={['pl', 'fr']}
        googleApiKey={GOOGLE_API_KEY} 
        onSelect={place => this.setState({place})} 
    />

Limit results to a location

    <PlacesInput
        placeHolder={'Some placeholder'}
        searchRadius={500}
        searchLatitude={51.905070}
        searchLongitude={19.458834}
        googleApiKey={GOOGLE_API_KEY} 
        onSelect={place => this.setState({place})} 
    />

Place types

    <PlacesInput
        placeHolder={'Some placeholder'}
        queryTypes="establishment"
        googleApiKey={GOOGLE_API_KEY} 
        onSelect={place => this.setState({place})} 
    />

Keywords

input

FAQs

Package last updated on 15 Mar 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts