2018-01-05 14:53:03 +01:00
# `nearby(location, [opt])`
2017-12-17 18:16:04 +01:00
This method can be used to find stations close to a location. Note that it is not supported by every profile/endpoint.
2021-08-18 15:59:43 +02:00
`location` must be an [*FPTF* `location` object ](https://github.com/public-transport/friendly-public-transport-format/blob/3bd36faa721e85d9f5ca58fb0f38cdbedb87bbca/spec/readme.md#location-objects ).
2017-12-17 18:16:04 +01:00
With `opt` , you can override the default options, which look like this:
```js
{
2018-10-15 17:34:25 +02:00
results: 8, // maximum number of results
2017-12-17 18:16:04 +01:00
distance: null, // maximum walking distance in meters
poi: false, // return points of interest?
2019-01-23 12:58:05 +08:00
stops: true, // return stops/stations?
2020-03-18 20:04:39 +01:00
subStops: true, // parse & expose sub-stops of stations?
entrances: true, // parse & expose entrances of stops/stations?
2019-01-23 13:03:01 +08:00
linesOfStops: false, // parse & expose lines at each stop/station?
2018-07-09 12:40:38 +02:00
language: 'en' // language to get results in
2017-12-17 18:16:04 +01:00
}
```
## Response
2018-01-05 15:01:32 +01:00
As an example, we're going to use the [VBB profile ](../p/vbb ):
2017-12-17 18:16:04 +01:00
```js
const createClient = require('hafas-client')
const vbbProfile = require('hafas-client/p/vbb')
2018-07-19 21:55:03 +02:00
const client = createClient(vbbProfile, 'my-awesome-program')
2017-12-17 18:16:04 +01:00
2021-12-29 16:59:31 +01:00
await client.nearby({
2018-01-05 14:53:03 +01:00
type: 'location',
latitude: 52.5137344,
longitude: 13.4744798
}, {distance: 400})
2017-12-17 18:16:04 +01:00
```
2021-12-29 16:59:31 +01:00
The result may look like this:
2017-12-17 18:16:04 +01:00
```js
[ {
2018-07-11 00:32:57 +02:00
type: 'stop',
2017-12-17 18:16:04 +01:00
id: '900000120001',
name: 'S+U Frankfurter Allee',
location: {
type: 'location',
latitude: 52.513616,
longitude: 13.475298
},
products: {
suburban: true,
subway: true,
tram: true,
bus: true,
ferry: false,
express: false,
regional: false
},
distance: 56
}, {
2018-07-11 00:32:57 +02:00
type: 'stop',
2017-12-17 18:16:04 +01:00
id: '900000120540',
name: 'Scharnweberstr./Weichselstr.',
location: {
type: 'location',
latitude: 52.512339,
longitude: 13.470174
},
products: { /* … */ },
distance: 330
}, {
2018-07-11 00:32:57 +02:00
type: 'stop',
2017-12-17 18:16:04 +01:00
id: '900000160544',
name: 'Rathaus Lichtenberg',
location: {
type: 'location',
latitude: 52.515908,
longitude: 13.479073
},
products: { /* … */ },
distance: 394
} ]
```