Get User Position

Retrieve the estimated Woosmap Latitude/Longitude for the current user
  1. Retrieve the user position
  2. Implementation

Retrieve the user position



<script src=""></script>
(publicKey => {
    woosmapRecommendation.getConsent((consent) => {
        if (consent === true) {
                successCallback(latlng) {
                    if ('latitude' in latlng) {
                        userPositionMap.src = `//|${latlng.latitude},${latlng.longitude}&zoom=14&size=600x400&maptype=roadmap&key=XXX`;
                    } else {
                        userPositionMap.src = "/assets/images/no_map.png";
        } else if (consent === false) {
            // invite the user to accept your privacy policy/cookies 
            // before optIn him to Woosmap recommendation 
            // using woosmapRecommendation.optIn();

The above code does four main things:

  1. Synchronously downloads the recommendation.js JavaScript library from

  2. Initializes the Recommendation process with setProjectKey(publicKey) for the project specified via the 'WOOS-XXXX-YYYY' parameter. This method GET or CREATE the Woosmap User Id Cookie.

  3. Get the Woosmap estimated user position with getUserPosition({successCallback}). The successCallback(latlng) method is called if the request returns without errors. But this does not mean Woosmap found the user position. You have to check for latlng Object is not empty. (if ('latitude' in latlng) in this sample).

  4. Display a Google Static Map centered on the returned user position.