Recommendation

Get User Position

Retrieve the estimated Woosmap Latitude/Longitude for the current user

Retrieve the user position

loading

Implementation

<script src="https://recommendation-js.woosmap.com/recommendation.js"></script>
<script>
(function (publicKey) {
    woosmapRecommendation.setProjectKey(publicKey);
    woosmapRecommendation.getUserPosition({
        successCallback: function (latlng) {
            if ('latitude' in latlng) {
                userPositionMap.src = '//maps.googleapis.com/maps/api/staticmap?markers=icon:https://images.woosmap.com/user-position.png|' 
                    + latlng.latitude + ',' + latlng.longitude+ '&zoom=14&size=600x400&maptype=roadmap&key=XXX';
            }
            else {
                userPositionMap.src = "/img/no_map.png";
            }

        }
    });
})('WOOS-XXXX-YYYY');
</script>

The above code does four main things:

  1. Synchronously downloads the recommendation.js JavaScript library from https://recommendation-js.woosmap.com/recommendation.js.

  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.