mirror of
				https://github.com/public-transport/db-vendo-client.git
				synced 2025-11-04 01:56:33 +02:00 
			
		
		
		
	query nearby locations
This commit is contained in:
		
							parent
							
								
									7c7fb53b55
								
							
						
					
					
						commit
						cd8d2ec297
					
				
					 1 changed files with 35 additions and 1 deletions
				
			
		
							
								
								
									
										36
									
								
								index.js
									
										
									
									
									
								
							
							
						
						
									
										36
									
								
								index.js
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -121,7 +121,41 @@ const createClient = (profile) => {
 | 
			
		|||
		})
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return {departures, journeys, locations}
 | 
			
		||||
	const nearby = (latitude, longitude, opt = {}) => {
 | 
			
		||||
		if ('number' !== typeof latitude) throw new Error('latitude must be a number.')
 | 
			
		||||
		if ('number' !== typeof longitude) throw new Error('longitude must be a number.')
 | 
			
		||||
		opt = Object.assign({
 | 
			
		||||
			results: 8, // maximum number of results
 | 
			
		||||
			distance: null, // maximum walking distance in meters
 | 
			
		||||
			poi: false, // return points of interest?
 | 
			
		||||
			stations: true, // return stations?
 | 
			
		||||
		}, opt)
 | 
			
		||||
 | 
			
		||||
		return request(profile, {
 | 
			
		||||
			cfg: {polyEnc: 'GPA'},
 | 
			
		||||
			meth: 'LocGeoPos',
 | 
			
		||||
			req: {
 | 
			
		||||
				ring: {
 | 
			
		||||
					cCrd: {
 | 
			
		||||
						x: profile.formatCoord(longitude),
 | 
			
		||||
						y: profile.formatCoord(latitude)
 | 
			
		||||
					},
 | 
			
		||||
					maxDist: opt.distance || -1,
 | 
			
		||||
					minDist: 0
 | 
			
		||||
				},
 | 
			
		||||
				getPOIs: !!opt.poi,
 | 
			
		||||
				getStops: !!opt.stations,
 | 
			
		||||
				maxLoc: opt.results
 | 
			
		||||
			}
 | 
			
		||||
		})
 | 
			
		||||
		.then((d) => {
 | 
			
		||||
			if (!Array.isArray(d.locL)) return []
 | 
			
		||||
			const parse = profile.parseNearby
 | 
			
		||||
			return d.locL.map(loc => parse(profile, loc))
 | 
			
		||||
		})
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return {departures, journeys, locations, nearby}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
module.exports = createClient
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		
		Reference in a new issue