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

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.

$.ajax({
    url: 'https://api.woosmap.com/geolocation/position/',
    type: 'GET',
    dataType:'json',
    data: {
        key:[YOUR_PUBLIC_KEY]
    },
    success: function(geoloc) {
        console.log(geoloc);
    }
});

Server-side requests

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

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

Response

The Response is a formated JSON containing the keys: country_code, country_name, continent, city, region_state

According to IP data relevance, JSON can contain the keys latitude, longitude

{
    "country_code": "FR",
    "country_name": "France",
    "continent": "Europe",
    "city": "My City",
    "region_state": "my-region",
    "latitude": 44.9759,
    "longitude": -93.2166
}

Example

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

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