Skip to content

Commit 2cae797

Browse files
author
swiftcomplete-public
committed
Added groupByCompass parameter
1 parent e78c292 commit 2cae797

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,9 @@ swiftcompleteReverseGeocoder.reverseGeocode('51.499403,-0.127362').then(function
9393

9494
It's possible to pass in an optional options object to customise the response. Each field is optional within the object:
9595

96-
- maxResults - Max number of results to return (up to 5, default: 1). Note that you are billed per result, so 4 results = 4 charges.
9796
- distanceUnits - Unit of measurement to display how far away the address is from your coordinate ("metric", "imperial", "m", "km", "ft", "mi", default: "metric")
97+
- groupByCompass - Enabling groupByCompass returns addresses surrounding your coordinate, rather than just the closest. Useful to return an overview of an area and ignore several addresses that are grouped together (true, false, default: "false")
98+
- maxResults - Max number of results to return (up to 5, default: 1). Note that you are billed per result, so 4 results = 4 charges.
9899

99100
```js
100101
const swiftcompleteReverseGeocoder = require('@swiftcomplete/reverse-geocode');

index.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,14 +158,20 @@ exports.reverseGeocode = function (coordinate, options) {
158158
let parsedDistanceUnits = parseDistanceUnits(options.distanceUnits);
159159

160160
if (parsedDistanceUnits.length > 0)
161-
url += `&distanceUnits=${parsedDistanceUnits}`;
161+
url += `&distanceUnits=${encodeURIComponent(parsedDistanceUnits)}`;
162+
}
163+
164+
if ('groupByCompass' in options) {
165+
let parsedGroupByCompass = options.groupByCompass == true;
166+
167+
url += `&groupByCompass=${encodeURIComponent(parsedGroupByCompass)}`;
162168
}
163169

164170
if ('maxResults' in options) {
165-
let parsedMaxResults = parseInt(options.maxResults);
171+
let parsedMaxResults = parseInt(encodeURIComponent(options.maxResults);
166172

167173
if (!isNaN(parsedMaxResults) && parsedMaxResults >= 1 && parsedMaxResults <= 5)
168-
url += `&maxResults=${parsedMaxResults}`;
174+
url += `&maxResults=${encodeURIComponent(parsedMaxResults)}`;
169175
}
170176
}
171177

0 commit comments

Comments
 (0)