Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/conveyal/isomorphic-mapzen-search
Isomorphic Mapzen search for reuse across our JavaScript libraries.
https://github.com/conveyal/isomorphic-mapzen-search
geocoder openstreetmap
Last synced: 2 months ago
JSON representation
Isomorphic Mapzen search for reuse across our JavaScript libraries.
- Host: GitHub
- URL: https://github.com/conveyal/isomorphic-mapzen-search
- Owner: conveyal
- License: mit
- Created: 2016-01-26T08:51:08.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2023-02-03T23:02:20.000Z (almost 2 years ago)
- Last Synced: 2024-09-18T11:46:45.917Z (4 months ago)
- Topics: geocoder, openstreetmap
- Language: TypeScript
- Size: 2.74 MB
- Stars: 5
- Watchers: 4
- Forks: 6
- Open Issues: 17
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# isomorphic-mapzen-search
Isomorphic Mapzen search for reuse across our JavaScript libraries. As Mapzen has shutdown, please use this library with [Pelias](https://pelias.io/). Coordinates must be anything that can be parsed by [lonlng](https://github.com/conveyal/lonlng).
- [Examples](#examples)
- [API Documentation](#api)## Examples
### `Autocomplete`
```js
import {autocomplete} from 'isomorphic-mapzen-search'autocomplete({
apiKey: MAPZEN_API_KEY,
boundary: {
country: 'US',
rect: {
minLon: minLon,
minLat: minLat,
maxLon: maxLon,
maxLat: maxLat
}
},
focusPoint: {lat: 39.7691, lon: -86.1570},
layers: 'venue,coarse',
text: '1301 U Str'
}).then((result) => {
console.log(result)
}).catch((err) => {
console.error(err)
})
```### `search({apiKey, text, ...options})`
```js
import {search} from 'isomorphic-mapzen-search'search({
apiKey: MAPZEN_API_KEY,
text: '1301 U Street NW, Washington, DC',
focusPoint: {lat: 39.7691, lon: -86.1570},
boundary: {
country: 'US',
rect: {
minLon: minLon,
minLat: minLat,
maxLon: maxLon,
maxLat: maxLat
},
circle: {
centerPoint: centerLonLat,
radius: 35 // kilometers
}
},
format: false // keep as returned GeoJSON
}).then((geojson) => {
console.log(geojson)
}).catch((err) => {
console.error(err)
})
```### `reverse({apiKey, point, format})`
```js
import {reverse} from 'isomorphic-mapzen-search'reverse({
apiKey: MAPZEN_API_KEY,
point: {
lat: 39.7691,
lng: -86.1570
},
format: true
}).then((json) => {
console.log(json[0].address)
}).catch((err) => {
console.error(err)
})
```## API
### autocomplete
Search for and address using
Mapzen's [Autocomplete](https://mapzen.com/documentation/search/autocomplete/)
service.**Parameters**
- `$0` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)**
- `$0.apiKey` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** The Mapzen API key
- `$0.boundary` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)**
- `$0.focusPoint` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)**
- `$0.format` **[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)**
- `$0.layers` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** a comma-separated list of
[layer types](https://mapzen.com/documentation/search/autocomplete/#layers)
- `$0.options` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** options to pass to fetch (e.g., custom headers)
- `$0.sources` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)?** (optional, default `'gn,oa,osm,wof'`)
- `$0.text` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** query text
- `$0.url` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)?** optional URL to override Mapzen autocomplete endpoint (optional, default `'https://search.mapzen.com/v1/autocomplete'`)Returns **[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)** A Promise that'll get resolved with the autocomplete result
### search
Search for an address using
Mapzen's [Search](https://mapzen.com/documentation/search/search/)
service.**Parameters**
- `$0` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)**
- `$0.apiKey` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** The Mapzen API key
- `$0.boundary` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)**
- `$0.focusPoint` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)**
- `$0.format` **[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)**
- `$0.options` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** options to pass to fetch (e.g., custom headers)
- `$0.size` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)?** (optional, default `10`)
- `$0.sources` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)?** (optional, default `'gn,oa,osm,wof'`)
- `$0.text` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** The address text to query for
- `$0.url` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)?** optional URL to override Mapzen search endpoint (optional, default `'https://search.mapzen.com/v1/search'`)Returns **[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)** A Promise that'll get resolved with search result
### reverse
Reverse geocode using
Mapzen's [Reverse geocoding](https://mapzen.com/documentation/search/reverse/)
service.**Parameters**
- `$0` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)**
- `$0.apiKey` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** The Mapzen API key
- `$0.format` **[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)**
- `$0.options` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** options to pass to fetch (e.g., custom headers)
- `$0.point` **{lat: [number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number), lon: [number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)}** Point to reverse geocode
- `$0.url` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)?** optional URL to override Mapzen reverse endpoint (optional, default `'https://search.mapzen.com/v1/reverse'`)Returns **[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)** A Promise that'll get resolved with reverse geocode result