Certainly! There are several APIs available that provide latitude and longitude data based on IP addresses. Here are a few options, including both free and paid services:
Free APIs
-
ipinfo.io
- Free Tier: 50,000 requests per month.
-
Endpoint:
https://ipinfo.io/{IP}/json -
Example:
fetch('https://ipinfo.io/8.8.8.8/json?token=YOUR_TOKEN') .then(response => response.json()) .then(data => console.log(data));
-
ipstack
- Free Tier: 5,000 requests per month.
-
Endpoint:
http://api.ipstack.com/{IP}?access_key=YOUR_ACCESS_KEY -
Example:
fetch('http://api.ipstack.com/8.8.8.8?access_key=YOUR_ACCESS_KEY') .then(response => response.json()) .then(data => console.log(data));
-
ip-api
- Free Tier: 45 requests per minute.
-
Endpoint:
http://ip-api.com/json/{IP} -
Example:
fetch('http://ip-api.com/json/8.8.8.8') .then(response => response.json()) .then(data => console.log(data));
Paid APIs
-
MaxMind GeoIP2 Precision
- Pricing: Starts at $0.0001 per query.
-
Endpoint:
https://geoip.maxmind.com/geoip/v2.1/city/{IP} -
Example:
fetch('https://geoip.maxmind.com/geoip/v2.1/city/8.8.8.8', { headers: { 'Authorization': 'Basic ' + btoa('YOUR_ACCOUNT_ID:YOUR_LICENSE_KEY') } }) .then(response => response.json()) .then(data => console.log(data));
-
ipdata.co
- Pricing: Starts at $10 for 1,500 requests per day.
-
Endpoint:
https://api.ipdata.co/{IP}?api-key=YOUR_API_KEY -
Example:
fetch('https://api.ipdata.co/8.8.8.8?api-key=YOUR_API_KEY') .then(response => response.json()) .then(data => console.log(data));
Summary
For a free solution with a generous limit, you might want to start with ipinfo.io or ip-api. If you need more requests or additional features, consider a paid service like MaxMind GeoIP2 Precision or ipdata.co.
Make sure to replace placeholders like YOUR_TOKEN, YOUR_ACCESS_KEY, YOUR_ACCOUNT_ID, YOUR_LICENSE_KEY, and YOUR_API_KEY with your actual API keys or credentials.