Get the User's Device Position

Retrieve the estimated Woosmap Latitude/Longitude for the current user’s device.

  1. Introduction
  2. Retrieve the user’s device position
  3. Implementation


The Geolocation API is designed to allow you to find the location of your users thanks to the IP address of their devices. This page shows you how to use the Geolocation API to provide a personalized and local experience to your visitors.

Adding the following code to your site’s templates is the easiest way to get started using Geolocation API. The /geolocation/position/ endpoint returns a json object with the Woosmap estimated Latitude and Longitude for the current user. Please, check the Geolocation Docs to see how to use this in more detail.

Retrieve the user’s device position


const woosmapKey = "woos-xyz123...";
$(document).ready(function() {
     url: '',
     type: 'GET',
     dataType: 'json',
     data: {
       key: woosmapKey
     success: function(position) {
       if (position.latitude) {
         // check accuracy (units in km) to accept or not position - according to your usecase. 
         if (position.accuracy >= 200) {/*accuracy not sufficient*/} 
         else if(position.accuracy >= 50) {/*acceptable accuracy*/}
         else {/*good accuracy*/} 

The above code calls When returns successful, this does not mean Woosmap found an accurate position. You have to verify position.latitude Object is not empty and check the position.accuracy.

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