Skip to content

Add support for no_annotations to OpenCage geocoder #265

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/geocoder/opencagegeocoder.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,10 @@ OpenCageGeocoder.prototype._getCommonParams = function () {
params.language = this.options.language;
}

if (typeof this.options.noAnnotations !== 'undefined') {
params.no_annotations = this.options.noAnnotations;
}

return params;
};

Expand Down
2 changes: 1 addition & 1 deletion lib/geocoder/virtualearth.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ VirtualEarthGeocoder.prototype._reverse = function(value, callback) {
key: this.options.apiKey
};

var endpoint = this._endpoint + "/" + value.lat + "," + value.lon;
var endpoint = this._endpoint + '/' + value.lat + ',' + value.lon;

this.httpAdapter.get(endpoint, params, function(err, result) {
if (err) {
Expand Down
2 changes: 1 addition & 1 deletion test/geocoder/mapquestgeocoder.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@

var mock = sinon.mock(mockedHttpAdapter);
mock.expects('get').withArgs(
'http://www.mapquestapi.com/geocoding/v1/address',
'https://www.mapquestapi.com/geocoding/v1/address',
{ key: "API_KEY", location: "test" }
).once().returns({then: function() {}});

Expand Down
40 changes: 39 additions & 1 deletion test/geocoder/opencagegeocoder.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,25 @@

});

test('Should make a request with no_annotations option', () => {

var mock = sinon.mock(mockedHttpAdapter);
mock.expects('get').withArgs('http://api.opencagedata.com/geocode/v1/json', {
key: 'API_KEY',
q: '1 champs élysée Paris',
no_annotations: 1,
}).once().returns({then: function (err,result) {}});

var ocgAdapter = new OpenCageGeocoder(mockedHttpAdapter, 'API_KEY', {
noAnnotations: 1
});

ocgAdapter.geocode('1 champs élysée Paris');

mock.verify();

});

test(
'Should call httpAdapter get method with components if called with object',
() => {
Expand Down Expand Up @@ -215,10 +234,29 @@
done();
});
});

});

describe('#reverse' , () => {

test('Should make a request with no_annotations option', () => {

var mock = sinon.mock(mockedHttpAdapter);
mock.expects('get').withArgs('http://api.opencagedata.com/geocode/v1/json', {
key: 'API_KEY',
q: '13.3826786867678 52.51921145',
no_annotations: 1,
}).once().returns({then: function (err,result) {}});

var ocgAdapter = new OpenCageGeocoder(mockedHttpAdapter, 'API_KEY', {
noAnnotations: 1
});

ocgAdapter.reverse({lat:13.3826786867678, lon:52.51921145});

mock.verify();

});

test('Should return geocoded address', done => {
var mock = sinon.mock(mockedHttpAdapter);
mock.expects('get').once().callsArgWith(2, false, {
Expand Down