Cartographer
This package tries to make integration with different map providers easier by returning the same result whether you are using gmaps, osm, etc.
Install
npm i cartographer
How to use
Google maps
Get here your API Key
const { createGmaps } = require('cartographer')
const gmaps = createGmaps({
params: { key: 'YOUR_GMAPS_API_KEY_HERE' }
})
const result = await gmaps.search('Barcelona')
Open Street Map
const { createOSM } = require('cartographer')
const osm = createOSM()
const result = await osm.search('Barcelona')
In the case of osm you can request the geojson of a location by passing their osmId
:
const geojson = await osm.searchGeoJSON(347950)
Also, if you have an osm object (raw) you can pass it to get an updated response. The method will take from the object the osm_id
and the osm_type
to collect the osm info:
const result = await osm.searchGeoJSON({
osm_id:"347950",
osm_type:"relation"
})
Common search response for all integrations (Location Objects)
const result = [{
address: String,
lon: Number,
lat: Number,
bbox: [
[Number, Number],
[Number, Number]
],
raw: {}
}]