Get User's Device Location
How to get location of a user's device from its ip addressOverview
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_key
in 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, latitude, longitude, accuracy, viewport, postal_code, timezone
latitude, longitude
values are approximate latitude and longitude of the geographical area associated with the IP address.
accuracy
value is the approximate accuracy radius, in kilometers, around the latitude and longitude associated with the IP address.
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.