IP Geolocation API showing a location found from an IP address

IP Geolocation API - Get Location From IP

Retrieve user location data with API

IP Geolocation API lets you get a city-level location for your customers.

You can get location from IP and use this data to customize your website or app settings based on your customer's location, including map view, currency, and language. With accurate city-level location data and additional country information, our API is a powerful tool for enhancing location-based functionality.

For example, you can determine that your customer is located in Germany and close to Berlin. You could show them local offers in Berlin, communicate with them in German, or suggest nearby events or attractions.

Try IP Geolocation API

This demo shows your location on a map and returns the IP address associated with your request. You can also provide an IP address to API, which will return that IP's location:

How does IP Geolocation work?

IP Geolocation (or Internet Geolocation) is the process of identifying the physical location of a device using its Internet Protocol (IP) address.

An IP address is the address a device or network uses on the internet, and many devices can share one. When a desktop computer or mobile device makes an HTTP request and calls API, its IP address is provided as a part of the request. So the API can see it even if it's not added explicitly.

IP Geolocation API works by using an IP address to determine the approximate geographic location of a device. The API uses a combination of databases, algorithms, and geolocation technologies to find information about the location associated with that IP address. This information typically includes the country, region, city, and even the latitude and longitude coordinates of the device.

IP Geolocation technology is often used in various applications to customize user experiences based on their geographic location, such as displaying local content, offering personalized deals, or detecting and preventing fraud.

How to find a location from an IP address

Send the IP address in the ip parameter:

https://api.geoapify.com/v1/ipinfo?ip=129.6.15.28&apiKey=YOUR_API_KEY

If you leave out ip, the API uses the IP address of whoever sends the request. Called from a browser, that's your visitor's IP address. Called from a backend, it's your server's IP address, so pass your visitor's IP address in ip instead.

IP Geolocation vs Browser Geolocation

IP Geolocation and Browser Geolocation are two different methods of determining a device's location.

Browser Geolocation determines a device's location using data collected by the device's browser. This method relies on the user's permission to access location data, and it typically uses a combination of GPS, Wi-Fi, and cellular data to provide more accurate location information.

While both IP Geolocation and Browser Geolocation can be used to personalize user experiences based on location, Browser Geolocation typically provides more accurate results than IP Geolocation.

However, Browser Geolocation requires user permission, whereas IP Geolocation does not, making it a valuable alternative for situations where user consent is not possible or practical.

What the response includes

The API returns a JSON object with the IP address it looked up, its approximate location and details about the country:

  • Location: city, state, postal and location with latitude and longitude.
  • Country: name, ISO code, phone code, capital, currency, flag and languages.
  • Continent: code and name.
  • Translations: names objects with place names in several languages.

Here is a shortened response for ip=129.6.15.28, a public NIST time server that NIST lists in Gaithersburg, Maryland. The names objects and some country fields are left out:

{
  "ip": "129.6.15.28",
  "city": { "name": "Gaithersburg" },
  "state": { "name": "Maryland" },
  "postal": { "code": "20899" },
  "country": {
    "name": "United States",
    "iso_code": "US",
    "phone_code": "1",
    "capital": "Washington D.C.",
    "flag": "🇺🇸",
    "languages": [
      {
        "iso_code": "en",
        "name": "English",
        "name_native": "English"
      }
    ]
  },
  "continent": { "code": "NA", "name": "North America" },
  "location": { "latitude": 39.1402, "longitude": -77.2185 }
}

The response doesn't include a street address, the internet provider, a VPN flag or the owner of the IP address. See all fields in the API reference.

Use Cases

IP geolocation is a versatile technology that can be applied in a wide range of use cases, from personalizing online experiences to improving security measures. Here are some of them:

Show map based on user location

Presenting a familiar and well-accepted map view to customers can improve their user experience by allowing them to navigate and interact with the map easily. In addition, by providing a pre-set view, customers can save time and effort that would have otherwise been spent scrolling and searching for the desired location.

E-commerce

E-commerce websites can use our IP address lookup API to personalize product offerings and pricing based on a customer's location. This can include showing products and prices in the local currency, highlighting local promotions and deals, and offering location-specific shipping options.

Fraud prevention

Businesses can use IP Geolocation to identify and prevent fraudulent activity, such as identifying suspicious login attempts from locations not associated with the user's usual location.

Website localization

You can use our API to get location from IP to automatically display website content in the user's preferred language based on their location. This can improve user experience and increase engagement.

Advertising

IP Geolocation can be used to deliver targeted ads based on a user's location. This can include displaying location-specific ads for local businesses or targeting users in specific regions with ads for relevant products or services.

Content distribution

IP Geolocation can be used to distribute content based on a user's location. This can include delivering local news, weather, sports updates, and streaming content licensed for specific regions.

Getting started with IP address lookup API

The IP Geolocation API can be accessed through a simple HTTP Get request, making it compatible with any programming language or operating system:

Step 1. Register and get an API Key

To use the API, you need an API Key which you can get by following these steps:

  • Register on the MyProject Geoapify page.
  • Create a new project.
  • Go to the "API keys" section and get your API key.

For more information on how to create a project, generate an API key, and get started with the Maps API, visit the Getting Started with Maps API page.

Step 2. Call HTTP GET API request

Here are some examples of code in various programming languages that demonstrate how to make API calls to the IP Geolocation service:

fetch('https://api.geoapify.com/v1/ipinfo?apiKey=YOUR_API_KEY')
.then(resp => resp.json())
.then((userLocationData) => {
	console.log(userLocationData);
});

You can generate code samples easily on our Playground page. For parameters and response fields, see the API reference.

Pricing

We use a credit-based system to simplify the pricing structure and provide a predictable cost for our users.

Each IP Geolocation API call costs one credit: 1 IP Geolocation = 1 credit.

With our Freemium pricing model, you can make up to 3,000 IP Geolocation calls per day for free. If you need more credits, we offer affordable Pricing Plans to fit any business size.

Guides

These guides solve common tasks with the IP Geolocation API, with ready-to-run requests.

01

Use it in the browser

Start the page with the visitor's country and city, without a permission prompt.

02

Use it on your server

Pass the client IP from your backend, with proxies, caching and privacy handled.

IP Geolocation API Tutorials

Get started quickly and easily with our IP Geolocation API using the following tutorials:

JavaScript developers can leverage user location data to create dynamic web apps that adjust map views, show nearby points of interest, and offer personalized recommendations

How to Get User Location with JavaScript: A Comprehensive Guide

Get visitor location on your website with JavaScript. Explore methods like navigator.geolocation, IP geolocation, and more with practical examples
Geolocation technology has many benefits for users, but also some risks

What is Geolocation: How It Works and Its Many Uses

Learn how geolocation technology works, its uses, and the benefits and risks of collecting user location data. Explore its applications and learn the best practices.

Still not sure how to begin? If you're encountering any issues or have questions, we're here to help! Contact us, and we’ll be happy to assist.

IP Location Lookup API FAQ

How accurate is the IP Geolocation API?

Geoapify IP Geolocation API returns a city-level user location that corresponds to map zoom levels 10-11. Also, the API provides useful information about the country, such as the ISO code, country name, and more. See the API reference.

How do I find a location from an IP address?

Send a GET request to "https://api.geoapify.com/v1/ipinfo" with the IP address in the "ip" parameter and your API key. The response has the city, state, country and approximate coordinates.

How can I get my own public IP address with the API?

Call the API without the "ip" parameter. It uses the IP address of whoever sends the request and returns it in the "ip" field, together with the location.

How do I call the API from a server?

Pass your visitor's IP address in the "ip" parameter. Without it, the API looks up your server's IP address instead of your visitor's.

Is it possible to detect a user location more precisely?

You can detect user location more precisely by using the HTML Geolocation service which is natively provided by all modern browsers. This can be useful for getting up-to-date information and turn-by-turn navigation. However, the location information is provided only after user permission, i.e after the user presses the “Allow“ button in the popup.

Is Geoapify IP Geolocation Free to use?

We have a Freemium pricing model. The Free plan includes 3,000 credits per day, and each IP Geolocation request costs 1 credit, so you can make up to 3,000 requests per day for free.

Can I use the Free Plan for commercial projects?

Yes. You can use the Free plan for commercial projects, including in production, within the plan's usage and feature limits. Provide a follow-link to Geoapify near the geolocation information, such as “Powered by Geoapify”, and retain any required data-source attribution. See the commercial-use FAQ and attribution requirements for details.

Which versions of IP do you support?

We support both IPv4 and IPv6 addresses. See the API reference.

How to get user location in JavaScript?

Geoapify IP Geolocation and Browser Geolocation are two methods of getting user location in JavaScript. The Geoapify IP Geolocation API allows you to detect a user's location based on their IP address, while Browser Geolocation uses the HTML Geolocation service natively provided by modern browsers to get a more precise location with user permission. The choice of which method to use depends on the level of accuracy needed and user permission requirements.

Can the API return the user's exact street address?

No, the API returns city-level location information, not the user's exact street address, and it doesn't identify a person. This is due to privacy concerns and limitations in the accuracy of IP geolocation.

Is an IP address personal data?

An IP address can be personal data under GDPR, so check how your application collects and uses it. How Geoapify handles request data is described in our Privacy Policy.

World map

Ready to get started?

Get an API key and add IP Geolocation to your project!