In this code example we are going to see how we can obtain the public IP of a visitor with their location data using the api.apify.org and ipwhois.app API using Javascript with Fetch requests showing the data on the screen through a grid formed with CSS so that we can view the data obtained through the 2 APIs at all times.
Table of Contents
ToggleIP + Location query example:

You can use the example code to use in your apps or learn how to use these location APIS, which are often useful when we want to work with filters or results using location data directly in our front-end.
Example code:
Get IP and Location data with Javascript
IP:
City:
Mainland:
Country:
Country_capital:
Country_code:
Country_phone:
Currency:
Currency_rates:
ISP:
Latitude:
Longitude:
Region:
Timezone:
The APIS used in the example are free as of April 16, 2022. This is important since these types of APIS usually transition to premium methods quite easily or are limited to X requests per day. It is advisable to review the documentation of each API to know limits or prices according to our needs.
Observations:
In the same way that we are obtaining the data using Fetch directly on the front end, we can also use the same urls to make Curls requests from the backend with another type of programming language such as php or python.
Did you find this information useful? Follow me on my social networks for more content like this. And if you have questions or know another way to do it, I encourage you to comment on this post.