Get User's Device Location

How to get location of a user’s device from its ip address

  1. Overview
  2. Client-side requests
  3. Server-side requests
  4. Response
  5. Example
  6. Usage limits

Overview

Woosmap Geolocation API can provide the location of your users thanks to IP address of their devices. You can query the API using a public or a private key according to your use case and calls origins.

Client-side requests

For client-side requests, use your public key (parameter key) related to your project.

const woosmapKey = "woos-xxx...";

fetch(
    `https://api.woosmap.com/geolocation/position/?
   key=${woosmapKey}`
)
    .then(result => result.json())
    .then((position) => {
        console.log(position);
    });

Server-side requests

For server-side requests, get the position of a specific ip address using a private_key in your requests.

curl 'https://api.woosmap.com/geolocation/position/?private_key={private_key}&ip_address={ip_to_geolocalize}'

Response

For a provided location, the response is a formatted JSON containing the keys:

country_code ISO 3166-1 Alpha-2 compatible country code
country_name country name (string value)
continent continent name (string value)
region_state region name when available (string value)
city city name (string value) when available
postal_code a postal code close to the user’s location, when available
timezone the time zone associated with location, as specified by the IANA Time Zone Database
latitude longitude approximate latitude and longitude of the geographical area associated with the IP address
accuracy radius in kilometers around the specified location where the IP address is likely to be
viewport geographic bounds (northeast latlng and southwest latlng) build from latitude, longitude and accuracy values, to help center a map

According to IP data relevance and accuracy some keys may eventually not be provided.

{
  "country_code": "FR",
  "country_name": "France",
  "continent": "Europe",
  "city": "My City",
  "region_state": "my-region",
  "latitude": 51.507527,
  "longitude": -0.127942,
  "accuracy": 20,
  "postal_code": "75000",
  "timezone": "Europe/Paris",
  "viewport": {
    "northeast": {
      "lat": 51.640551,
      "lng": 0.072636
    },
    "southwest": {
      "lat": 51.373665,
      "lng": -0.320715
    }
  }
}

Example

Here is a sample of a Geolocation API call using Javascript. The fetched location is used to generate a Google static map.

Usage limits

The following usage limits are in place for the location endpoint of Geolocation API:

Was this article helpful?
Have more questions? Submit a request