1.6.1 • Published 4 years ago
isomorphic-mapzen-search v1.6.1
isomorphic-mapzen-search
Isomorphic Mapzen search for reuse across our JavaScript libraries. As Mapzen has shutdown, please use this library with Pelias. Coordinates must be anything that can be parsed by lonlng.
Examples
Autocomplete
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})
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})
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 service.
Parameters
$0Object$0.apiKeystring The Mapzen API key$0.boundaryObject$0.focusPointObject$0.formatboolean$0.layersstring a comma-separated list of layer types$0.optionsObject options to pass to fetch (e.g., custom headers)$0.sourcesstring? (optional, default'gn,oa,osm,wof')$0.textstring query text$0.urlstring? optional URL to override Mapzen autocomplete endpoint (optional, default'https://search.mapzen.com/v1/autocomplete')
Returns Promise A Promise that'll get resolved with the autocomplete result
search
Search for an address using Mapzen's Search service.
Parameters
$0Object$0.apiKeystring The Mapzen API key$0.boundaryObject$0.focusPointObject$0.formatboolean$0.optionsObject options to pass to fetch (e.g., custom headers)$0.sizenumber? (optional, default10)$0.sourcesstring? (optional, default'gn,oa,osm,wof')$0.textstring The address text to query for$0.urlstring? optional URL to override Mapzen search endpoint (optional, default'https://search.mapzen.com/v1/search')
Returns Promise A Promise that'll get resolved with search result
reverse
Reverse geocode using Mapzen's Reverse geocoding service.
Parameters
$0Object$0.apiKeystring The Mapzen API key$0.formatboolean$0.optionsObject options to pass to fetch (e.g., custom headers)$0.point{lat: number, lon: number} Point to reverse geocode$0.urlstring? optional URL to override Mapzen reverse endpoint (optional, default'https://search.mapzen.com/v1/reverse')
Returns Promise A Promise that'll get resolved with reverse geocode result