Socket
Socket
Sign inDemoInstall

@geoapify/react-geocoder-autocomplete

Package Overview
Dependencies
6
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @geoapify/react-geocoder-autocomplete

React component for the Geoapify Geocoder Autocomplete field


Version published
Weekly downloads
610
decreased by-17.9%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

React Geocoder Autocomplete

The @geoapify/react-geocoder-autocomplete component serves as an interface to the @geoapify/geocoder-autocomplete library, seamlessly integrating its capabilities into React-based applications. This integration harnesses the power of the Geoapify Geocoding Autocomplete service for advanced address search functionality.

Address autocomplete is a feature that enhances user experience and accuracy when entering location-based information, particularly addresses. It's a technology often used in web and mobile applications to assist users in quickly and accurately inputting addresses by providing real-time suggestions as they type.

Geocoder Autocomplete

Installation

@geoapify/react-geocoder-autocomplete relies on @geoapify/geocoder-autocomplete as a peer dependency. To include both packages in your project, you can use the following commands:

Using npm:

npm install @geoapify/geocoder-autocomplete @geoapify/react-geocoder-autocomplete

Using Yarn:

yarn add @geoapify/geocoder-autocomplete @geoapify/react-geocoder-autocomplete

This ensures that both the React wrapper and the underlying geocoder-autocomplete library are correctly installed and compatible with each other in your project.

Compatibility Table

@geoapify/react-geocoder-autocompleteReact
1.0.x>= 16.8.0
1.1.x>= 16.8.0
1.2.x>= 17.0.0
1.3.x>= 17.0.0
1.4.x>= 18.0.0
1.5.x>= 18.0.0
2.0.x>= 18.0.0

This table provides compatibility information between different versions of @geoapify/react-geocoder-autocomplete and the required minimum version of React. Make sure to choose the appropriate version based on your React project's version.

Certainly, here's a complete "Getting Started" guide for using the @geoapify/react-geocoder-autocomplete library in your React project:

Getting Started

Geoapify Geocoder Autocomplete simplifies address search in your React applications. Follow these steps to get started:

Obtaining Your API Key

Before integrating the @geoapify/react-geocoder-autocomplete library into your project, you must acquire an API key from Geoapify. Here's a step-by-step guide:

  1. Register for a Geoapify Account: If you don't already have a Geoapify account, visit Geoapify My Projects and sign up for a free account.

  2. Create a New Project: After registering and logging in, create a new project in your Geoapify account.

  3. Generate an API Key: Within your project settings, you can generate a new API key. Customize the key's settings according to your project's requirements. Once configured, generate the API key. Be sure to copy it because you'll need it to authenticate and use Geoapify services in your React project.

Integrate the Geocoder Autocomplete Component

To integrate the @geoapify/react-geocoder-autocomplete component into your React project, follow these steps:

  1. Import Styles: Import the CSS style file from @geoapify/geocoder-autocomplete to ensure the control appears correctly. You can choose from various styles like minimal, round-borders, minimal-dark, or round-borders-dark, depending on your webpage's background color.

    import '@geoapify/geocoder-autocomplete/styles/minimal.css';
    
  2. Add Geoapify Context and Provide API Key: Wrap your component with the GeoapifyContext and provide your Geoapify API key as a prop. This context will enable the component to authenticate and use Geoapify services.

    import { GeoapifyContext } from '@geoapify/react-geocoder-autocomplete';
    
    // Inside your component...
    <GeoapifyContext apiKey="YOUR_API_KEY_HERE">
      {/* Your Geoapify Geocoder Autocomplete components go here */}
    </GeoapifyContext>
    

    Replace "YOUR_API_KEY_HERE" with your actual Geoapify API key.

  3. Add Geoapify Geocoder Autocomplete Component: You can add one or more instances of the GeoapifyGeocoderAutocomplete component within the GeoapifyContext. Customize the component by passing various props like placeholder, value, type, lang, and more, based on your specific requirements.

    Here's an example of using the component with different props and callback functions:

import '@geoapify/geocoder-autocomplete/styles/minimal.css';
import {
  GeoapifyGeocoderAutocomplete,
  GeoapifyContext
} from '@geoapify/react-geocoder-autocomplete';

...
 <GeoapifyContext apiKey="YOUR_API_KEY">
  <GeoapifyGeocoderAutocomplete
    placeholder="Enter address here"
    value={value}
    type={type}
    lang={language}
    position={position}
    countryCodes={countryCodes}
    limit={limit}
    filterByCountryCode={filterByCountryCode}
    filterByCircle={filterByCircle}
    filterByRect={filterByRect}
    filterByPlace={filterByPlace}
    biasByCountryCode={biasByCountryCode}
    biasByCircle={biasByCircle}
    biasByRect={biasByRect}
    biasByProximity={biasByProximity}
    placeSelect={onPlaceSelect}
    suggestionsChange={onSuggestionChange}
  />
</GeoapifyContext>

Customize the props to meet your project's needs, and handle events like placeSelect and suggestionsChange by specifying callback functions as shown in the example.

Optionally, you can use preprocessing and postprocessing hooks, as well as suggestions filtering, by providing the respective functions as props to the GeoapifyGeocoderAutocomplete component. These functions allow you to modify user input and search results to fit your application's requirements.

By following these steps and configuring the GeoapifyGeocoderAutocomplete component with the necessary props and callbacks, you can seamlessly integrate address autocomplete functionality into your React project while customizing it to your specific needs.

API documentation

Here are the props for the GeoapifyGeocoderAutocomplete component:

PropTypeDescription
placeholderstringPlaceholder text for the input field.
typeGeocoderAutocomplete.LocationTypeThe type of location to search for (e.g., 'city', 'postcode', 'street'). Default is 'city'.
langGeocoderAutocomplete.SupportedLanguageThe language for search suggestions. Default is 'en'.
limitnumberThe maximum number of suggestions to display. Default is 5.
valuestringThe initial input value.
filterByCountryCodeGeocoderAutocomplete.ByCountryCodeOptionsFilter suggestions by country code(s).
filterByPlacestringFilter suggestions by a specific place (e.g., 'New York').
filterByCircleGeocoderAutocomplete.ByCircleOptionsFilter suggestions by a circular area.
filterByRectGeocoderAutocomplete.ByRectOptionsFilter suggestions by a rectangular area.
biasByCountryCodeGeocoderAutocomplete.ByCountryCodeOptionsBias suggestions by country code(s).
biasByCircleGeocoderAutocomplete.ByCircleOptionsBias suggestions by a circular area.
biasByRectGeocoderAutocomplete.ByRectOptionsBias suggestions by a rectangular area.
biasByProximityGeocoderAutocomplete.ByProximityOptionsBias suggestions by proximity to a location.
debounceDelaynumberDelay in milliseconds to wait for user input before triggering suggestions. Default is 100.
skipIconsbooleanWhether to skip displaying icons in suggestions. Default is false.
addDetailsbooleanWhether to add detailed place information to suggestions. Default is false.
skipSelectionOnArrowKeybooleanWhether to skip selecting suggestions when using arrow keys. Default is false.
allowNonVerifiedHouseNumberbooleanWhether to allow non-verified house numbers in suggestions. Default is false.
allowNonVerifiedStreetbooleanWhether to allow non-verified streets in suggestions. Default is false.
placeSelect(value: GeoJSON.Feature) => voidCallback function when a place is selected.
suggestionsChange(values: GeoJSON.Feature[]) => voidCallback function when suggestions change.
preprocessHook(value: string) => stringPreprocessing hook for user input.
postprocessHook(feature: GeoJSON.Feature) => stringPostprocessing hook for selected suggestions.
suggestionsFilter(suggestions: GeoJSON.Feature[]) => any[]Custom filter for suggestions.
sendGeocoderRequestFunc(value: string, geocoderAutocomplete: GeocoderAutocomplete) => Promise<GeoJSON.FeatureCollection>Custom function to send geocoder requests.
sendPlaceDetailsRequestFunc(feature: GeoJSON.Feature, geocoderAutocomplete: GeocoderAutocomplete) => Promise<GeoJSON.Feature>Custom function to send place details requests.
onUserInput(input: string) => voidCallback function when user input changes.
onOpen(opened: boolean) => voidCallback function when the suggestions dropdown opens.
onClose(opened: boolean) => voidCallback function when the suggestions dropdown closes.

These props allow you to configure and customize the behavior of the GeoapifyGeocoderAutocomplete component in your React application.

You can apply multiple filters simultaneously, and the AND logic is used to combine these filters. Similarly, you can utilize multiple bias parameters concurrently, and the OR logic is employed to combine these biases.

The component does not have a dependency on @types/geojson. Nevertheless, you have the option to install it if you intend to work with GeoJSON types.

Explore More:

Keywords

FAQs

Last updated on 28 Sep 2023

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc