react-geosuggest, react-google-maps, and react-leaflet address distinct layers of the geospatial stack in React applications. react-geosuggest is a specialized input component that wraps Google Places Autocomplete to provide address prediction and selection, focusing purely on the search experience without rendering a map. react-google-maps acts as a React-friendly wrapper around the official Google Maps JavaScript API, enabling complex map interactions, custom overlays, and deep integration with the Google ecosystem. react-leaflet provides a React interface for Leaflet, an open-source JavaScript library for interactive maps, offering a lightweight, vendor-neutral alternative that avoids proprietary licensing fees while delivering robust core mapping features.
Choosing the right geospatial tool in React depends heavily on whether you need an input field, a full map, and which map provider you trust. The three packages react-geosuggest, react-google-maps, and react-leaflet solve different problems. Let's break down their architectural roles, maintenance status, and real-world implementation patterns.
Before writing any code, you must address the lifecycle status of these libraries. react-google-maps is deprecated. The maintainers have officially archived the project and recommend migrating to other solutions.
Using react-google-maps in new projects is strongly discouraged. It lacks support for modern React features (like concurrent mode) and will not receive security patches or updates for new Google Maps API versions.
// ❌ DO NOT USE in new projects
import { Map, Marker } from 'react-google-maps';
// ✅ Recommended alternative for Google Maps
import { LoadScript, GoogleMap, Marker } from '@react-google-maps/api';
In contrast, react-geosuggest and react-leaflet are actively maintained and safe for production use. react-leaflet specifically tracks updates to the underlying Leaflet library, ensuring compatibility with modern web standards.
The most common architectural mistake is confusing an autocomplete input with a map renderer. react-geosuggest and the other two packages operate at different layers of the UI stack.
react-geosuggest is purely an input component. It renders a text box with a dropdown list of predicted addresses. It does not render a map tile layer. You use this when you need to capture structured location data from a user.
// react-geosuggest: Only renders an input field
import Geosuggest from 'react-geosuggest';
const AddressInput = () => (
<Geosuggest
placeholder="Start typing a location"
onSuggestSelect={(suggest) => console.log(suggest)}
location={{ lat: 53.558572, lng: 9.992222 }}
radius="20"
/>
);
react-leaflet and react-google-maps render the actual map canvas. They handle tile loading, zooming, panning, and overlay rendering. You use these when the user needs to visually explore a geographic area or interact with spatial data.
// react-leaflet: Renders a full interactive map
import { MapContainer, TileLayer, Marker, Popup } from 'react-leaflet';
const InteractiveMap = () => (
<MapContainer center={[51.505, -0.09]} zoom={13} style={{ height: '400px', width: '100%' }}>
<TileLayer
url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
attribution='© OpenStreetMap contributors'
/>
<Marker position={[51.505, -0.09]}>
<Popup>A simple marker on Leaflet.</Popup>
</Marker>
</MapContainer>
);
When you need a full map, your choice dictates your vendor relationship. react-google-maps (and its modern replacements) ties you to Google's infrastructure. react-leaflet keeps you vendor-neutral.
Google Maps Ecosystem requires an API key and billing account. It offers superior satellite imagery, street view, and advanced routing data. However, costs scale with usage, and you must comply with Google's terms of service.
// Google Maps approach (using modern wrapper @react-google-maps/api)
import { LoadScript, GoogleMap } from '@react-google-maps/api';
const GoogleMapInstance = () => (
<LoadScript googleMapsApiKey="YOUR_API_KEY">
<GoogleMap
mapContainerStyle={{ width: '100%', height: '400px' }}
center={{ lat: 40.7128, lng: -74.0060 }}
zoom={10}
>
{/* Markers and overlays here */}
</GoogleMap>
</LoadScript>
);
Leaflet Ecosystem is open source. It works with any tile provider (OpenStreetMap, Mapbox, Esri, or self-hosted tiles). This gives you full control over costs and data privacy. The trade-off is that you must source your own tile data and advanced features like routing require additional plugins.
// Leaflet approach: Vendor neutral
import { MapContainer, TileLayer } from 'react-leaflet';
const OpenMapInstance = () => (
<MapContainer center={[40.7128, -74.0060]} zoom={10} style={{ height: '400px', width: '100%' }}>
{/* Switch tile providers easily without changing logic */}
<TileLayer
url="https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}"
attribution="Tiles © Esri"
/>
</MapContainer>
);
The way these libraries expose functionality to React differs significantly, impacting how you manage state and side effects.
react-geosuggest follows a standard controlled/uncontrolled component pattern. It passes plain JavaScript objects to your callbacks. This makes it easy to integrate with form libraries like Formik or React Hook Form.
// react-geosuggest: Standard props and callbacks
<Geosuggest
initialValue="New York"
onSuggestSelect={(suggest) => {
// suggest object contains lat, lng, placeId, etc.
setFormData({ ...formData, location: suggest });
}}
onFocus={() => setIsFocused(true)}
onBlur={() => setIsFocused(false)}
/>
react-leaflet uses a component-based architecture that mirrors Leaflet's class structure but adapts it for React. It relies heavily on context to share the map instance between components (like Markers and Popups). You rarely need to access the underlying Leaflet map object directly, but you can via refs if needed.
// react-leaflet: Context-aware components
import { useMap } from 'react-leaflet';
function MapUpdater() {
const map = useMap(); // Accesses the map instance from context
useEffect(() => {
if (map) {
map.invalidateSize(); // Direct access to Leaflet methods
}
}, [map]);
return null;
}
react-google-maps (the deprecated version) used a complex higher-order component (HOC) pattern (withGoogleMap, withScriptjs) that often led to confusing prop drilling and lifecycle issues. This architectural complexity was a primary driver for its deprecation.
// react-google-maps: Legacy HOC pattern (Avoid this)
const MapWithHOC = withGoogleMap(() => (
<GoogleMap defaultZoom={12} defaultCenter={{ lat: 40.7, lng: -74.0 }}>
<Marker position={{ lat: 40.7, lng: -74.0 }} />
</GoogleMap>
));
When your application requires custom drawing tools, heatmaps, or complex vector layers, the underlying engine matters.
Leaflet has a massive ecosystem of plugins. Since react-leaflet wraps Leaflet directly, you can use almost any Leaflet plugin by wrapping it in a React component. This is ideal for specialized needs like drawing polygons, measuring distances, or displaying heatmaps.
// react-leaflet: Using a custom plugin wrapper
import { Polygon } from 'react-leaflet';
const ZonePolygon = () => (
<Polygon
positions={[
[51.505, -0.09],
[51.51, -0.1],
[51.51, -0.09]
]}
pathOptions={{ color: 'blue', fillColor: 'lightblue' }}
/>
);
Google Maps provides built-in support for advanced features like KML layers, StreetView, and sophisticated clustering without extra plugins. However, implementing custom canvas rendering or non-standard overlays can be more rigid compared to Leaflet's modular plugin system.
// Google Maps: Built-in advanced features
import { KmlLayer } from '@react-google-maps/api';
const KmlOverlay = () => (
<KmlLayer
url="http://example.com/overlay.kml"
options={{ preserveViewport: true }}
/>
);
| Feature | react-geosuggest | react-google-maps | react-leaflet |
|---|---|---|---|
| Primary Function | Address Autocomplete Input | Full Map Renderer | Full Map Renderer |
| Map Rendering | ❌ No | ✅ Yes (Google Tiles) | ✅ Yes (Any Tiles) |
| Maintenance Status | ✅ Active | ❌ Deprecated | ✅ Active |
| Cost Model | Free (uses Google Places API) | Pay-per-request | Free (Open Source) |
| Vendor Lock-in | High (Google Places) | High (Google Maps) | None (Vendor Neutral) |
| React Pattern | Standard Component | Legacy HOC (Avoid) | Context-based Components |
react-geosuggest is the specialist for data entry. Use it when you need to turn a text string into a verified coordinate. It pairs perfectly with react-leaflet — use the suggest component to find the address, then fly the Leaflet map to that location.
react-google-maps is a legacy artifact. Do not start new projects with it. If you need Google's specific data (Satellite, Street View), migrate to @react-google-maps/api or use the native API.
react-leaflet is the flexible workhorse for modern web apps. It offers the best balance of performance, cost control, and developer experience for most use cases. Its open architecture ensures you aren't trapped by vendor price hikes or API changes.
Final Thought: Your choice isn't just about features; it's about long-term maintainability. Combine react-geosuggest for input and react-leaflet for visualization to build a robust, cost-effective, and future-proof geospatial interface.
Choose react-geosuggest when your primary requirement is a high-quality address autocomplete input field rather than a full interactive map. It is the ideal solution for checkout forms, user profile editors, or any scenario where you need to validate and standardize user addresses using Google's Places database without the overhead of loading a full map engine. Avoid this package if you need to display map markers, draw polygons, or handle map events, as it does not render a map instance.
Select react-google-maps only if you are maintaining a legacy codebase that already depends on it, as the package is officially deprecated and no longer receives updates. For new projects requiring Google Maps features, this package should be avoided in favor of the official @react-google-maps/api wrapper or direct API usage to ensure long-term stability and access to the latest Google Maps features. Relying on this deprecated library introduces significant technical debt and potential security risks due to lack of maintenance.
Opt for react-leaflet when you need a full-featured interactive map without being locked into Google's pricing model or API key restrictions. It is the superior choice for dashboards, data visualization tools, and applications that require custom map tiles (such as OpenStreetMap) or complete control over the rendering engine. This package is best suited for teams that prioritize open-source standards, want to avoid per-request costs, and need a flexible component model that aligns well with modern React patterns.
A React autosuggest for the Google Maps Places API. You can also define your own suggests as defaults. Works with Preact, too.
Live demo: ubilabs.github.io/react-geosuggest
As this component uses the Google Maps Places API to get suggests, you must include the Google Maps Places API in the <head> of your HTML:
<!DOCTYPE html>
<html>
<head>
…
<script src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY_HERE&libraries=places"></script>
</head>
<body>
…
</body>
</html>
Visit the Google Developer Console to generate your API key. The API's that you have to enable in your Google API Manager Dashboard are Google Maps Geocoding API, Google Places API Web Service and Google Maps Javascript API.
The easiest way to use geosuggest is to install it from NPM and include it in your own React build process (using Webpack, Parcel, etc).
You can also use the standalone build by including dist/react-geosuggest.js in your page. If you use this, make sure you have already included React, and it is available as a global variable.
npm install react-geosuggest --save
The Geosuggest works out of the box by just including it. However, you can customize the behaviour with the properties noted below.
import Geosuggest from 'react-geosuggest';
<Geosuggest />
var Geosuggest = require('react-geosuggest').default;
<Geosuggest />
Type: String
Default: Search places
The input field will get this placeholder text.
Type: String
Default: ''
An initial value for the input, when you want to prefill the suggest.
Type: String
Default: ''
Define an ID for the geosuggest. Needed when there are multiple instances on a page.
Type: String
Default: ''
Add an additional class to the geosuggest container.
Type: Object
Default: { 'input': {}, 'suggests': {}, 'suggestItem': {} }
Add an additional style to Geosuggest.
This would support overriding/adding styles to the input suggestList and suggestItem.
Type: String
Default: ''
Add an additional class to the input.
Type: Boolean
Default: false
Defines whether the input is disabled.
Type: google.maps.LatLng
Default: null
To get localized suggestions, define a location to bias the suggests.
Type: Number
Default: 0
The radius in meters defines the area around the location to use for biasing the suggests. It must be accompanied by a location parameter.
Type: LatLngBounds
Default: null
The bounds to use for biasing the suggests. If this is set, location and radius are ignored.
Type: String or Array
Default: null
Restricts predictions to the specified country (ISO 3166-1 Alpha-2 country code, case insensitive). E.g., us, br, au. You can provide a single one, or an array of up to 5 country code strings.
Type: Array
Default: null
The types of predictions to be returned. Four types are supported: establishment for businesses, geocode for addresses, (regions) for administrative regions and (cities) for localities. If nothing is specified, all types are returned. Consult the Google Docs for up to date types.
Type: Array
Default: []
An array with fixtures (defaults). Each fixture has to be an object with a label key in it. Optionally provide a location, but the Geosuggest will geocode the label if no location is provided.
You can also add a className key to a fixture. This class will be applied to the fixture item.
Type: Number
Default: 10
Maximum number of fixtures to render.
Type: Array
Default: null
By default Google returns all fields when getting place details which can impact billing. You can optionally pass an array of fields to include in place results to limit what is returned and potentially reduce billing impact. geometry will always be added as we depend on the location for the suggest selection.
Type: Object
Default: google.maps
In case you want to provide your own Google Maps object, pass it in as googleMaps. The default is the global google maps object.
Type: Boolean
Default: false
When the tab key is pressed, the onSelect handler is invoked. Set to true to not invoke onSelect on tab press.
Type: Boolean
Default: false
When the enter key is pressed, the onSelect handler is invoked. Set to true to not invoke onSelect on enter press.
Type: Number
Default: 250
Sets the delay in milliseconds after typing before a request will be sent to find suggestions.
Specify 0 if you wish to fetch suggestions after every keystroke.
Type: Number
Default: 1
Sets a minimum length of characters before a request will be sent to find suggestions.
Type: Boolean
Default: true
Highlights matched text.
Type: Function
Default: function() {}
Gets triggered when the input field receives focus.
Type: Function
Default: function(value) {}
Gets triggered when input field loses focus.
Type: Function
Default: function(value) {}
Gets triggered when input field changes the value.
Type: Function
Default: function(event) {}
Gets triggered when input field has a key pressed down. This event is triggered before onKeyPress.
Type: Function
Default: function(event) {}
Gets triggered when input field gets key press.
Type: Function
Default: function(suggest) {}
Gets triggered when a suggest got selected. Only parameter is an object with data of the selected suggest. This data is available:
label – Type String – The label nameplaceId – Type String – If it is a preset, equals the label. Else it is the Google Maps placeIDlocation – Type Object – The location containing lat and lnggmaps – Type Object – Optional! The complete response when there was a Google Maps geocode necessary (e.g. no location provided for presets). Check the Google Maps Reference for more information on it’s structure.Type: Function
Default: function(suggests, activeSuggest) {}
Gets triggered when the suggest list changes. Arguments include the suggest list and the current activeSuggest. Useful if you want to render the list of suggests outside of react-geosuggest.
Type: Function
Default: function(suggest) {}
Gets triggered when a suggest is activated in the list. Only parameter is an object with data of the selected suggest. This data is available:
label – Type String – The label nameplaceId – Type String – If it is a preset, equals the label. Else it is the Google Maps placeIDType: Function
Default: function(userInput) {}
Gets triggered when there are no suggest results found
Type: Function
Default: function(suggest) { return suggest.description; }
Used to generate a custom label for a suggest. Only parameter is a suggest (google.maps.places.AutocompletePrediction). Check the Google Maps Reference for more information on it’s structure.
Type: Function
Default: null
Used to customize the inner html of SuggestItem and allows for controlling what properties of the suggest object you want to render. Also a convenient way to add additional styling to different rendered elements within SuggestItem. The function is passed both the suggestion and the user input.
Type: Function
Default: function(suggest) {}
If the function returns true then the suggest will not be included in the displayed results. Only parameter is an object with data of the selected suggest. (See above)
Type: Boolean
Default: false
Automatically activate the first suggestion as you type. If false, the exact term(s) in the input will be used when searching and may return a result not in the list of suggestions.
Type: String
Default: null
If the label and a id prop (see "Others") were supplied, a <label> tag with the passed label text will be rendered. The <label> element's for attribute will correctly point to the id of the <input> element.
Type: String
Default: ''
Add an additional class to suggest list.
Type: String
Default: null
Additional className to toggle as the list of suggestions changes visibility.
Type: String
Default: ''
Add an additional class to suggest item.
Type: String,
Default: null
Additional className to add when a suggestion item is active.
Type: String,
Default: nope
Autocomplete input attribute.
Type: String,
Default: text
The value for the type attribute on the html input element. Can be either text or search.
All allowed attributes for input[type="text"]
All DOM clipboard events.
All DOM mouse events except for drag & drop.
All data attributes.
These functions are accessible by setting "ref" on the component (see example below)
Call focus to focus on the element. The suggest list will be expanded with the current suggestions.
Call blur to blur (unfocus) the element. The suggest list will be closed.
It is possible to update the value of the input contained within the GeoSuggest component by calling the update function with a new desired value of the type String.
It is also possible to clear the value of the input contained within the GeoSuggest component by calling the clear function.
Same effect as hitting enter (will geocode the text inside of the input).
import React, {useRef} from 'react';
import ReactDOM from 'react-dom';
import Geosuggest from 'react-geosuggest';
const App = () => {
const geosuggestEl = useRef(null);
const fixtures = [
{label: 'New York', location: {lat: 40.7033127, lng: -73.979681}},
{label: 'Rio', location: {lat: -22.066452, lng: -42.9232368}},
{label: 'Tokyo', location: {lat: 35.673343, lng: 139.710388}}
];
/**
* When a suggest got selected
*/
const onSuggestSelect = (suggest) => console.log(suggest);
return (
<div>
<Geosuggest
ref={geosuggestEl}
placeholder="Start typing!"
initialValue="Hamburg"
fixtures={fixtures}
onSuggestSelect={onSuggestSelect}
location={new google.maps.LatLng(53.558572, 9.9278215)}
radius="20" />
{* Buttons to trigger exposed component functions *}
<button onClick={()=>geosuggestEl.current.focus()}>Focus</button>
<button onClick={()=>geosuggestEl.current.update('New Zealand')}>Update</button>
<button onClick={()=>geosuggestEl.current.clear()}>Clear</button>
<button onClick={()=>geosuggestEl.current.selectSuggest()}>Search</button>
</div>
);
};
ReactDOM.render(<App />, document.getElementById('app'));
This component uses BEM for namespacing the CSS classes. So styling should be easy and without conflicts. See the geosuggest.css for an example styling.
The geosuggest__suggests--hidden class is added to hide the suggestion list. You should copy the style below into your CSS file.
.geosuggest__suggests--hidden {
max-height: 0;
overflow: hidden;
border-width: 0;
}
The above class is added whenever the suggestion list needs to be hidden. This occurs when the user selects an item from the list or when the user triggers the blur event on the input.
Similarly, you need to have the class geosuggest__item--active similar to this:
.geosuggest__item--active {
background: #267dc0;
color: #fff;
}
to see what item is selected, f.ex. when using the arrow keys to navigate the suggestion list.
Issues and pull requests are welcome! Please read the guidelines in CONTRIBUTING.md before starting to work on a PR.
See LICENSE.md