Skip to content
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

HERE: adding maxResults option #317

Merged
merged 1 commit into from
Jan 29, 2021
Merged
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: 2 additions & 2 deletions spec/here.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ describe('L.Control.Geocoder.HERE', () => {
const geocoder = new HERE({ app_id: 'xxx', app_code: 'yyy' });
const callback = jest.fn();
testXMLHttpRequest(
'https://geocoder.api.here.com/6.2/geocode.json?searchtext=Innsbruck&gen=9&app_id=xxx&app_code=yyy&jsonattributes=1',
'https://geocoder.api.here.com/6.2/geocode.json?searchtext=Innsbruck&gen=9&app_id=xxx&app_code=yyy&jsonattributes=1&maxresults=5',
{
response: {
view: [
Expand Down Expand Up @@ -93,7 +93,7 @@ describe('L.Control.Geocoder.HEREv2', () => {
const geocoder = new HEREv2({ apiKey: 'xxx', geocodingQueryParams: geocodingParams });
const callback = jest.fn();
testXMLHttpRequest(
'https://geocode.search.hereapi.com/v1/discover?q=Innsbruck&apiKey=xxx&at=50.62925%2C3.057256',
'https://geocode.search.hereapi.com/v1/discover?q=Innsbruck&apiKey=xxx&limit=10&at=50.62925%2C3.057256',
{
items: [
{
Expand Down
17 changes: 12 additions & 5 deletions src/geocoders/here.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export interface HereOptions extends GeocoderOptions {
app_code: string;
reverseGeocodeProxRadius?: any;
apiKey: string;
maxResults: number;
}

/**
Expand All @@ -32,7 +33,8 @@ export class HERE implements IGeocoder {
serviceUrl: 'https://geocoder.api.here.com/6.2/',
app_id: '',
app_code: '',
apiKey: ''
apiKey: '',
maxResults: 5
};

constructor(options?: Partial<HereOptions>) {
Expand All @@ -46,7 +48,8 @@ export class HERE implements IGeocoder {
gen: 9,
app_id: this.options.app_id,
app_code: this.options.app_code,
jsonattributes: 1
jsonattributes: 1,
maxresults: this.options.maxResults
});
this.getJSON(this.options.serviceUrl + 'geocode.json', params, cb, context);
}
Expand All @@ -62,14 +65,16 @@ export class HERE implements IGeocoder {
app_id: this.options.app_id,
app_code: this.options.app_code,
gen: 9,
jsonattributes: 1
jsonattributes: 1,
maxresults: this.options.maxResults
});
this.getJSON(this.options.serviceUrl + 'reversegeocode.json', params, cb, context);
}

getJSON(url: string, params: any, cb: GeocodingCallback, context?: any) {
getJSON(url, params, data => {
const results: GeocodingResult[] = [];

if (data.response.view && data.response.view.length) {
for (let i = 0; i <= data.response.view[0].result.length - 1; i++) {
const loc = data.response.view[0].result[i].location;
Expand Down Expand Up @@ -99,7 +104,8 @@ export class HEREv2 implements IGeocoder {
serviceUrl: 'https://geocode.search.hereapi.com/v1',
apiKey: '',
app_id: '',
app_code: ''
app_code: '',
maxResults: 10
};

constructor(options?: Partial<HereOptions>) {
Expand All @@ -109,7 +115,8 @@ export class HEREv2 implements IGeocoder {
geocode(query: string, cb: GeocodingCallback, context?: any): void {
const params = geocodingParams(this.options, {
q: query,
apiKey: this.options.apiKey
apiKey: this.options.apiKey,
limit: this.options.maxResults
});

if (!params.at && !params.in) {
Expand Down