Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
react-geoinput
Advanced tools
Geolocation suggestions and coordinates with Google Maps API for React
Redux-form compatible geolocation suggestions and coordinates with Google Maps API.
input
interface (compatible with redux-form
)react-geoinput
as dependencynpm install --save react-geoinput
Make window.google.maps
available e.g. with:
<script src="https://maps.googleapis.com/maps/api/js?libraries=places&key=YOUR_API_KEY_HERE"></script>
link: Google Maps JavaScript API / get API key
$ git clone https://github.com/woltapp/react-geoinput.git
$ cd react-geoinput
$ yarn
$ yarn start
1_quickstart
demonstrates the use of DefaultGeoInput
2_barebones
uses only createGeoInput
and demonstrates how to use the API to create your own inputReact-geoinput makes it a breeze to combine both geolocation suggestion and geocoding an address. Generally other libraries do only either at once. A good use case for this library is to be able to turn an address into coordinates and verify that the interpreted address was correct in textual format. Moreover, this library allows complete customization of the UI, and only provides components to get you quickly started!
import React, { Component } from 'react';
import { createGeoInput, DefaultGeoInput } from 'react-geoinput';
const SimpleInput = createGeoInput(DefaultGeoInput);
class Example extends Component {
state = {
address: '',
geoDestination: '',
}
onAddressChange = value => this.setState({ address: value })
onGeoDestinationChange = value => this.setState({ geoDestination: value })
render() {
return (
<div>
<SimpleInput
addressInput={{
onChange: this.onAddressChange,
value: this.state.address,
}}
geoDestinationInput={{
onChange: this.onGeoDestinationChange,
value: this.state.geoDestination,
}}
/>
</div>
);
}
}
import React from 'react';
import { Fields } from 'redux-form';
import { createGeoInput, DefaultGeoInput } from 'react-geoinput';
const GeoInput = createGeoInput(DefaultGeoInput);
const GeoField = fields => (
<GeoInput
addressInput={fields.address.input}
geoDestinationInput={fields.destination.input}
/>
);
Use with redux-form
's Fields
component:
<Fields names={['address', 'destination']} component={GeoField} />
React-geoinput exposes one higher order component (createGeoInput
) and three regular
stateless React components (DefaultGeoInput
, GeoAddressInput
, PredictiveInput
).
createGeoInput
contains the main logic to handle fetching location
suggestions from the Google Maps API and to geocode the typed
address to a location object, which includes e.g. coordinates and parsed
location fields. In fact, createGeoInput
provides two inputs simultaneously:
typed address and geocoded location. Generally you'll want to store the information
separately, since address is the arbitrary string typed by user and location
is the accurate exact geolocation.
DefaultGeoInput
exists to get you quickly started with the library. It contains
opinionated styles and structure, which is a good starting point. If it works
for you, you can customize it via the props, otherwise you can use
it simply as a starting point to create your own completely custom input component.
DefaultGeoInput
uses GeoAddressInput
underneath to provide the bare-bones
input with predictions (=suggestions).
GeoAddressInput
is provided as a convenience component, which simply maps
the predictions (suggestions) from createGeoInput()
to PredictiveInput
.
PredictiveInput
is provided as a utility component to provide a simple
input field with predictions -- it is not coupled to geocoding or locations anyhow.
It should be applicable for most cases and supports styling via props.
PredictiveInput
uses DebounceInput
from react-debounce-input
to reduce
the amount of requests made to the Google Maps API.
createGeoInput(input: Component, <options: Object>)
createGeoInput
is a higher order component that takes two arguments, first of which is your custom input (or DefaultGeoInput
),
and the second one is options object. It can be wrapped with a custom input component, such as with the provided DefaultGeoInput
. The beef of this library's logic is in this HoC; thus you are encouraged to make a custom implementation of the input.
serializePrediction
(Function): A function that takes prediction
object
from the Google Maps API as an argument and turns it into a string that is suggested.
The structure of the prediction
object is not included in this documentation.
serializeGeoDestination
(Function): A function that takes geoDestination
object
from the Google Maps API as an argument and turns it to another object. By default it maps
the geoDestination
keys as following: route->street
, street_number->streetNumber
,
subpremise->subpremise
, locality->city
, country->country
, postal_code->postalCode
,
{ geometry }->{ lat, lng},viewport
. The structure of the geoDestination
object is not
included in this documentation.
Note: you won't need to change these options unless you know you are missing an important value from the Google Maps API.
DefaultGeoInput
DefaultGeoInput
displays an input for typing the address. Predictions (=suggestions) will
be shown for the address with PredictiveInput
. On predicted address selection the geoDestionation
will be also rendered.
Note: a good way to get started with your completely custom input is to copy the implementation of
DefaultGeoInput
and modify it.
activeIndex (number)
: control the selected index of location suggestionaddressInput (object.isRequired)
: input controls, such as onChange
, value
className (string)
geoDestinationInput (object.isRequired)
: input controls, such as onChange
, value
geoDestinationClassName (string)
geoDestinationTableClassName (string)
loadingElement (node)
: element to display while loading geo destinationloadingGeoDestination (bool)
: control when to show loadingElement
onPredictionClick (func.isRequired)
: handle suggestion click, takes prediction index
predictions (array.isRequired)
: array of predictions from Google Maps APIstyle (object)
GeoAddressInput
activeIndex (number)
: control the selected index of location suggestionclassName (string)
onPredictionClick (func.isRequired)
: handles prediction click, takes prediction index
onChange (func.isRequired)
: handle for address input changepredictions (array.isRequired)
: array of predictions from Google Maps APIstyle (object)
PredictiveInput
className (string)
containerClassName (string)
:containerStyle (object)
:debounceTimeout (number)
: time for debounce in msactivePredictionId (string|number)
: control active predictionpredictions (arrayOf(predictionPropType))
: array of predictions (see below)predictionsClassName (string)
predictionItemClassName (string)
predictionPropType = PropTypes.shape({
id: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
label: PropTypes.node,
onClick: PropTypes.func,
})
MIT
FAQs
Geolocation suggestions and coordinates with Google Maps API for React
The npm package react-geoinput receives a total of 3 weekly downloads. As such, react-geoinput popularity was classified as not popular.
We found that react-geoinput demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.