Skip to content

Commit 8d28ecc

Browse files
Daredzikperliedman
authored andcommitted
Add option for prox radius when geocoding position (#261)
* Add option for prox radius when geocoding position Add prox radius when reverse geocoding point, especially for gecode point that not inside the road. * prettier style Reformat code using prettier * Remove Number.isInteger Remove Number.isInteger - coz IE * prettier prettier * prettier prettier
1 parent dcb2211 commit 8d28ecc

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

src/geocoders/here.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
11
import L from 'leaflet';
22
import { getJSON } from '../util';
3-
43
export var HERE = L.Class.extend({
54
options: {
65
geocodeUrl: 'https://geocoder.api.here.com/6.2/geocode.json',
76
reverseGeocodeUrl: 'https://reverse.geocoder.api.here.com/6.2/reversegeocode.json',
87
app_id: '<insert your app_id here>',
98
app_code: '<insert your app_code here>',
109
geocodingQueryParams: {},
11-
reverseQueryParams: {}
10+
reverseQueryParams: {},
11+
reverseGeocodeProxRadius: null
1212
},
13-
1413
initialize: function(options) {
1514
L.setOptions(this, options);
1615
},
17-
1816
geocode: function(query, cb, context) {
1917
var params = {
2018
searchtext: query,
@@ -26,10 +24,13 @@ export var HERE = L.Class.extend({
2624
params = L.Util.extend(params, this.options.geocodingQueryParams);
2725
this.getJSON(this.options.geocodeUrl, params, cb, context);
2826
},
29-
3027
reverse: function(location, scale, cb, context) {
28+
var _proxRadius = this.options.reverseGeocodeProxRadius
29+
? this.options.reverseGeocodeProxRadius
30+
: null;
31+
var proxRadius = _proxRadius ? ',' + encodeURIComponent(_proxRadius) : '';
3132
var params = {
32-
prox: encodeURIComponent(location.lat) + ',' + encodeURIComponent(location.lng),
33+
prox: encodeURIComponent(location.lat) + ',' + encodeURIComponent(location.lng) + proxRadius,
3334
mode: 'retrieveAddresses',
3435
app_id: this.options.app_id,
3536
app_code: this.options.app_code,
@@ -39,7 +40,6 @@ export var HERE = L.Class.extend({
3940
params = L.Util.extend(params, this.options.reverseQueryParams);
4041
this.getJSON(this.options.reverseGeocodeUrl, params, cb, context);
4142
},
42-
4343
getJSON: function(url, params, cb, context) {
4444
getJSON(url, params, function(data) {
4545
var results = [],
@@ -65,7 +65,6 @@ export var HERE = L.Class.extend({
6565
});
6666
}
6767
});
68-
6968
export function here(options) {
7069
return new HERE(options);
7170
}

0 commit comments

Comments
 (0)