
Research
Security News
Malicious PyPI Package Exploits Deezer API for Coordinated Music Piracy
Socket researchers uncovered a malicious PyPI package exploiting Deezer’s API to enable coordinated music piracy through API abuse and C2 server control.
react-native-google-places-autocomplete
Advanced tools
Customizable Google Places autocomplete component for iOS and Android React-Native apps
The react-native-google-places-autocomplete package is a customizable React Native component that provides a Google Places autocomplete input field. It allows users to search for places and get location details using the Google Places API.
Autocomplete Input
This feature provides an input field where users can type in a location name, and it will suggest places using Google Places API. The code sample demonstrates how to set up the autocomplete input and handle the selection of a place.
import React from 'react';
import { GooglePlacesAutocomplete } from 'react-native-google-places-autocomplete';
const GooglePlacesInput = () => {
return (
<GooglePlacesAutocomplete
placeholder="Search"
onPress={(data, details = null) => {
console.log(data, details);
}}
query={{
key: 'YOUR_API_KEY',
language: 'en',
}}
/>
);
};
export default GooglePlacesInput;
Customizable Components
This feature allows customization of the autocomplete component, including styles and behavior. The code sample shows how to customize the input field, such as setting the minimum length for search, autofocus, and styling the input container.
import React from 'react';
import { GooglePlacesAutocomplete } from 'react-native-google-places-autocomplete';
const CustomGooglePlacesInput = () => {
return (
<GooglePlacesAutocomplete
placeholder="Search"
minLength={2}
autoFocus={false}
returnKeyType={'search'}
listViewDisplayed={false}
fetchDetails={true}
renderDescription={row => row.description}
onPress={(data, details = null) => {
console.log(data, details);
}}
query={{
key: 'YOUR_API_KEY',
language: 'en',
}}
styles={{
textInputContainer: {
width: '100%',
},
description: {
fontWeight: 'bold',
},
predefinedPlacesDescription: {
color: '#1faadb',
},
}}
/>
);
};
export default CustomGooglePlacesInput;
react-native-maps provides map components for React Native applications, allowing for the integration of maps and location-based features. While it does not offer autocomplete functionality, it can be used in conjunction with react-native-google-places-autocomplete to display selected locations on a map.
react-native-geolocation-service is a package that provides high accuracy geolocation features for React Native apps. It focuses on obtaining the device's current location rather than providing place autocomplete functionality, making it complementary to react-native-google-places-autocomplete.
react-native-google-places is another package that provides Google Places API integration for React Native. It offers similar functionalities to react-native-google-places-autocomplete, such as place search and details retrieval, but with a different API and potentially less customization options.
Customizable Google Places autocomplete component for iOS and Android React-Native apps
npm install react-native-google-places-autocomplete --save
Basic Address Search
import React from 'react';
import { Image, Text } from 'react-native';
import { GooglePlacesAutocomplete } from 'react-native-google-places-autocomplete';
const GooglePlacesInput = () => {
return (
<GooglePlacesAutocomplete
placeholder='Search'
onPress={(data, details = null) => {
// 'details' is provided when fetchDetails = true
console.log(data, details);
}}
query={{
key: 'YOUR API KEY',
language: 'en',
}}
/>
);
};
export default GooglePlacesInput;
You can also try the basic example in a snack here
Get Current Location
Extra step required!
If you are targeting React Native 0.60.0+ you must install either @react-native-community/geolocation
(link) or react-native-geolocation-service
(link).
Please make sure you follow the installation instructions there and add navigator.geolocation = require(GEOLOCATION_PACKAGE)
somewhere in you application before <GooglePlacesAutocomplete />
.
import React from 'react';
import { Image, Text } from 'react-native';
import { GooglePlacesAutocomplete } from 'react-native-google-places-autocomplete';
// navigator.geolocation = require('@react-native-community/geolocation');
// navigator.geolocation = require('react-native-geolocation-service');
const GooglePlacesInput = () => {
return (
<GooglePlacesAutocomplete
placeholder='Search'
onPress={(data, details = null) => {
// 'details' is provided when fetchDetails = true
console.log(data, details);
}}
query={{
key: 'YOUR API KEY',
language: 'en',
}}
currentLocation={true}
currentLocationLabel='Current location'
/>
);
};
export default GooglePlacesInput;
Search with predefined option
import React from 'react';
import { Image, Text } from 'react-native';
import { GooglePlacesAutocomplete } from 'react-native-google-places-autocomplete';
const homePlace = {
description: 'Home',
geometry: { location: { lat: 48.8152937, lng: 2.4597668 } },
};
const workPlace = {
description: 'Work',
geometry: { location: { lat: 48.8496818, lng: 2.2940881 } },
};
const GooglePlacesInput = () => {
return (
<GooglePlacesAutocomplete
placeholder='Search'
onPress={(data, details = null) => {
// 'details' is provided when fetchDetails = true
console.log(data, details);
}}
query={{
key: 'YOUR API KEY',
language: 'en',
}}
predefinedPlaces={[homePlace, workPlace]}
/>
);
};
export default GooglePlacesInput;
Limit results to one country
import React from 'react';
import { Image, Text } from 'react-native';
import { GooglePlacesAutocomplete } from 'react-native-google-places-autocomplete';
const GooglePlacesInput = () => {
return (
<GooglePlacesAutocomplete
placeholder='Search'
onPress={(data, details = null) => {
// 'details' is provided when fetchDetails = true
console.log(data, details);
}}
query={{
key: 'YOUR API KEY',
language: 'en',
components: 'country:us',
}}
/>
);
};
export default GooglePlacesInput;
GooglePlacesAutocomplete
can be easily customized to meet styles of your app. Pass styles props to GooglePlacesAutocomplete
with style object for different elements (keys for style object are listed below)
key | type |
---|---|
container | object (View) |
description | object (Text style) |
textInputContainer | object (View style) |
textInput | object (style) |
loader | object (View style) |
listView | object (ListView style) |
predefinedPlacesDescription | object (Text style) |
poweredContainer | object (View style) |
powered | object (Image style) |
separator | object (View style) |
row | object (View style) |
<GooglePlacesAutocomplete
placeholder='Enter Location'
minLength={2}
autoFocus={false}
returnKeyType={'default'}
fetchDetails={true}
styles={{
textInputContainer: {
backgroundColor: 'rgba(0,0,0,0)',
borderTopWidth: 0,
borderBottomWidth: 0,
},
textInput: {
marginLeft: 0,
marginRight: 0,
height: 38,
color: '#5d5d5d',
fontSize: 16,
},
predefinedPlacesDescription: {
color: '#1faadb',
},
}}
/>
Web support can be enabled via the requestUrl
prop, by passing in a URL that you can use to proxy your requests. CORS implemented by the Google Places API prevent using this library directly on the web. You can use a proxy server like CORS Anywhere or roll your own. Please be mindful of this limitation when opening an issue.
Note: The library expects the same response that the Google Maps API would return.
styles
parameterThis library does not use the iOS, Android or JS SDKs from Google. This comes with some Pros and Cons.
Pros:
Cons:
Please see the releases tab for the changelog information.
FAQs
Customizable Google Places autocomplete component for iOS and Android React-Native apps
The npm package react-native-google-places-autocomplete receives a total of 153,274 weekly downloads. As such, react-native-google-places-autocomplete popularity was classified as popular.
We found that react-native-google-places-autocomplete demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
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.
Research
Security News
Socket researchers uncovered a malicious PyPI package exploiting Deezer’s API to enable coordinated music piracy through API abuse and C2 server control.
Research
The Socket Research Team discovered a malicious npm package, '@ton-wallet/create', stealing cryptocurrency wallet keys from developers and users in the TON ecosystem.
Security News
Newly introduced telemetry in devenv 1.4 sparked a backlash over privacy concerns, leading to the removal of its AI-powered feature after strong community pushback.