react-native-gplaces
React Native library for utilizing Google's Autocomplete for Places.
Install
Notice: Geolocation must be linked, in React Native 0.60+ this is done automatically.
using npm
npm install --save react-native-gplaces @react-native-community/geolocation
using yarn
yarn add react-native-gplaces @react-native-community/geolocation
Importing
ES6
The module uses an ES6 style export statement, simply use import
to load the module.
;
ES5
If you're using an ES5 require statement to load the module, please add default
. Look here for more detail.
var GPlaces = default;
Usage
This package supports custom queries if you'd like to use them. For searching queries look here and queries for getting places look here.
Creating an instance
You can obtain a Google API key here.
const places = key: 'YOUR_GOOGLE_MAPS_API_KEY' // https://developers.google.com/maps/documentation/javascript/get-api-key;
Search for places
places
Search for places nearby
places
Get details for a Place
places
API
constructor GPlaces(options: Options): GPlaces
Constructor for creating an instance of the GPlaces class
request: (url?: string) => Promise<any> (@private)
Calling this method will fetch an URL and return a JSON response
autocompleteRequest: (options?: string) => Promise<ACResult[]> (@private)
Calling this method will fetch and return an array of results
search: (input?: string, query?: ACQuery | undefined) => Promise<ACResult[]>
Calling this method will search for places matching the input.
searchNearby: (input?: string, radius?: number, query?: ACQuery | undefined) => Promise<ACResult[]>
Calling this method will search for nearby places matching the input in a given radius. The default radius is 1000m / 1km.
getPlaceDetails: (placeid?: string, query?: PDQuery | undefined) => Promise<PDResult>
Calling this method will get certain details for a place based on a query.
Types
For up-to-date information about Autocomplete queries look here, for Place Details queries look here.