# Store Locator JS API - Distance code snippet function

**URL:** <https://forum.woosmap.com/t/store-locator-js-api-distance-code-snippet-function/22>\
**Category:** Ask the community\
**Tags:** store-locator, distance-api\
**Created:** [July 22, 2020, 1:11pm UTC](https://forum.woosmap.com/t/store-locator-js-api-distance-code-snippet-function/22 "2020-07-22T13:11:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![vfunnell](https://avatars.discourse-cdn.com/v4/letter/v/ad7895/32.png) [@vfunnell](https://forum.woosmap.com/u/vfunnell)\
**Post date:** [July 22, 2020, 1:11pm UTC](https://forum.woosmap.com/t/store-locator-js-api-distance-code-snippet-function/22/1 "2020-07-22T13:11:43Z")

</div>

I have looked at our documentation for API 1.4 of Store Locator JS API and cant find a suitable function for retrieving driving distance and time in the documentation.

Would you be able to provide a code snippet, to update stores with data from Distance API, similar to this function in [JS API v 1.4 | Woosmap Developers](https://developers.woosmap.com/products/js-api/reference/1.4/#woosmap.location.DistanceProvider) does?

---

<div class="post-metadata">

**Author:** ![gael](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.woosmap.com/gael/32/3_2.png) [@gael](https://forum.woosmap.com/u/gael)\
**Post date:** [July 22, 2020, 3:14pm UTC](https://forum.woosmap.com/t/store-locator-js-api-distance-code-snippet-function/22/2 "2020-07-22T15:14:28Z")

</div>

> **This topic is archived.** The Store Locator JS API discussed below has been retired, and the tutorial link at the end no longer resolves. The [Distance API](https://developers.woosmap.com/products/distance-api/tutorials/making-first-request/) still works as described here. To build the map itself, start with the [Map JS API](https://developers.woosmap.com/products/map-api/get-started/).

For now, the Woosmap Store Locator JS API does not include features from [Woosmap Distance API](https://developers.woosmap.com/products/distance-api/get-started/). But you can query the Distance API by yourself.

I’ve updated the [JS Store Locator sample app](https://demo.woosmap.com/storelocator/) to compute distance from a location (search from a user or geolocation) to a list of nearby stores, using the `/distancematrix/`endpoint from Woosmap Distance API.

Here you can have a look at the full code: [woosmap-starterkit-storelocator/app/src/init.js at master · Woosmap/woosmap-starterkit-storelocator · GitHub](https://github.com/woosmap/woosmap-starterkit-storelocator/blob/master/app/src/init.js#L433)

Below is the XHR call.

```js
let destinations = stores.map((store) => {
     return store.geometry.coordinates[1] + "," + store.geometry.coordinates[0]
});
woosmap.$.ajax({
     url: 'https://api.woosmap.com/distance/distancematrix/json?',
     type: 'GET',
     dataType: 'json',
     data: {
        origins: mapView.get('location').lat + "," + mapView.get('location').lng,
        destinations: destinations.join("|"),
        units: 'metric',
        mode: 'driving',
        language: 'en',
        elements: 'duration_distance',
        key: 'woos-XXX'
     },
     success: function (response) {
        if (response.status === "OK") {
          /*get your distance and duration values here*/
        }
     }
 });

```

and the results displayed with **distance** value and **duration**.

 ![image](https://europe1.discourse-cdn.com/flex013/uploads/woosmap/original/1X/d15fde3c83806d65304b6a7b728611cc110873c2.png)

We’ve also written a tutorial to help you build your own store locator : [Woosmap Documentation | Woosmap Developers](https://community.woosmap.com/build-a-store-locator/get-started/)

Thanks for joining us!

---

<div class="post-metadata">

**Author:** ![gael](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.woosmap.com/gael/32/3_2.png) [@gael](https://forum.woosmap.com/u/gael)\
**Post date:** [September 18, 2026, 2:43pm UTC](https://forum.woosmap.com/t/store-locator-js-api-distance-code-snippet-function/22/3 "2026-09-18T14:43:36Z")

</div>


