use-places-autocomplete | 😎 📍 React hook for Google Maps Places Autocomplete | Frontend Framework library
kandi X-RAY | use-places-autocomplete Summary
kandi X-RAY | use-places-autocomplete Summary
This is a React hook for Google Maps Places Autocomplete, which helps you build a UI component with the feature of place autocomplete easily! By leveraging the power of Google Maps Places API, you can provide a great UX (user experience) for user interacts with your search bar or form etc. Hope you guys it. ️ it? ️ it on GitHub or Tweet about it.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of use-places-autocomplete
use-places-autocomplete Key Features
use-places-autocomplete Examples and Code Snippets
Community Discussions
Trending Discussions on use-places-autocomplete
QUESTION
I want to use Google Maps and Places API in my React application for users to be able get hospitals in their area on the map.
I am using both @react-google-maps/api and use-places-autocomplete npm packages to interface with the API to display the map and places. I am using the useLoadScript hook to load in my API key and also declare libraries I will be using.
In this case, just as I have enabled Places and Maps JavaScript APIs, I supplied places in the libraries array.
I have tried adding the below script to the index.html file:
...ANSWER
Answered 2020-Nov-10 at 06:02If you are using useLoadScript
of the @react-google-maps/api library
and use-places-autocomplete
you need to supply the ['places'] as a value of your library to use the Places Autocomplete in your code. Please note that this useLoadScript
will load the Google Maps JavaScript Script tag in your code and you don't need to add the script tag in the html file anymore.
From what I understand, your use case where the user will select a place from the autocomplete dropdown and the nearest hospital should be returned in the map.
To achieve this, you need to have this flow:
- Use
use-places-autocomplete
to provide place suggestion when searching for a place. This library have aGetGeocode
and aGetLatLng
that you can use to get the coordinates of the chosen place. - Once you have the coordinates, you can use Places API Nearby Search, use the keyword
hospital
in your request and define a radius. This will search a list of hospital within the defined radius with the chosen place as the center. - You can loop through the list of result and pin each coordinates as markers in your map.
Here;s the sample code and a code snippet below. Make sure to add your API Key:
Index.js
QUESTION
I am still learning and am fairly confused with documentation and other SO questions that use Link in order to accomplish my goal of routing through my site on click from the landing page. I have circled back a few times fitting these concepts together and haven't yet figured out what I've done wrong.
index.js
...ANSWER
Answered 2020-Oct-15 at 00:00I needed to add:
QUESTION
I'm building out a Google Map on my Gatsby site with a search box that will allow users to search for their location. I've got a Hero
component and a Map
component, and all of the functionality is built into the Map
component; the Google Maps API, autocomplete, Google Places etc. Here's what it looks like right now:
Map.tsx
...ANSWER
Answered 2020-Jul-22 at 04:25Thanks for providing the sscce of your code in codesandbox. It looks like you are loading the Google Maps Javascript script tag only inside the and not inside
. You can see in your console log that there is a message to load the library.
To make it work, I used LoadScript of @react-google-maps/api in your index.tsx and put both and components in order for both script to work. Here's a sample of the index.tsx.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install use-places-autocomplete
usePlacesAutocomplete is based on the Places Autocomplete (or more specific docs) of Google Maps Place API. If you are unfamiliar with these APIs, we recommend you reviewing them before we start.
To use this hook, there're two things we need to do:.
Enable Google Maps Places API.
Get an API key.
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page