Finding Places From Current Location
We usually use Google Map to find restaurants or gas stations from our current location, but I am sure some have wondered how that is done. Here, we will find out. I will be using React to show this, as well as a Google API key.
First, an API key is needed to access the Google Maps API. The second step is we need to set our state with arbitrary latitude and longitude. See figure 1.

Next step is to determine our current location from using our “ComponentDidMount()” from figure 2.

Next, we want to see the current location. That is the purpose of “renderChildren()”. The “render()” will display everything. See figure 3.

The data will be sent to the file “MapContainer.js” where it will display the map. Now that we have our current location, we want to find places near our area. This will show up based on how much we zoomed in to our location. First you will need this piece of code from figure 4 to fetch places.

Final step is to display it. See figure 5.

Once we have the code from figure 5, we can see places nearby our current location. We can move anywhere around the map and it will show the places you desire.
The most important thing is we need the Google API key in the second line of figure 4 in order for it to work correctly. No key, no map.

From figure 6, we see the Google API key works. Try it out yourself.
References