Migrating from REST
This document provides a function mapping for customers migrating from our REST API to our JS SDK.
The sections below are titled with the REST function name and endpoint and details the equivalent JS SDK function or instructions on how to achieve the same result.
The samples linked below are all regular Javascript, but can be applied verbatim to whatever platform you use our SDK on. See the React Integration, Angular Integration and Node notes for integration on those platforms.
Finding POIs - By POI Property (/poi/get-all-ids?property)
There is no direct mapping for this function. However, by obtaining a list of All POIs, it is simply a matter of looping over the results and creating an array of all matching items.
Finding POIs - By Proximity (/search/by-proximity)
There is no direct function to conduct a proximity search in the SDK. If this functionality is required, we recommend that you cache the results of the All POIs call and then use the location data for each POI returned to identify POIs near a specific point. A standard lat/lon based distance calculation can be used for this purpose, as shown in the code snippet below:
window.LMInit = LMInit
var venuePOIs;
LMInit.newMap(null, config)
.then(m => {
window.map = m;
m.getAllPOIs().then(pois => {
venuePOIs = pois; // cache pois for later use
// Find pois in proximity to another poi, passing it in as well as a radius in meters
let poi = venuePOIs["66"];
let poisInProximity = findPOIsInProximity(poi, 20);
console.log("pois in proximity:", poisInProximity);
});
})
.catch(e => console.error('Error initializing map: ', e))
function findPOIsInProximity(poi, radiusM) {
let poiLat = poi.position["latitude"];
let poiLon = poi.position["longitude"];
let poiFloorID = poi.position["floorId"];
var poisInProximity = [];
// Find other pois in proximity, focussing only on selected categories
for (const [venuePOIID, venuePOI] of Object.entries(venuePOIs)) {
if (venuePOI.category != "eat" && venuePOI.category != "shop") continue;
let lat = venuePOI.position["latitude"];
let lon = poi.position["longitude"];
let floorID = poi.position["floorId"];
if (floorID != poiFloorID) continue; // POIs in proximity must be on the same floor
if (poiLat && poiLon && lat && lon) {
var distanceM = getDistanceM(poiLat, poiLon, lat, lon);
if (distanceM <= radiusM) poisInProximity.push(venuePOI);
}
}
return poisInProximity;
}
function getDistanceM(lat1, lon1, lat2, lon2) {
var R = 6371; // Radius of the earth in km
var dLat = deg2rad(lat2-lat1);
var dLon = deg2rad(lon2-lon1);
var a =
Math.sin(dLat/2) * Math.sin(dLat/2) +
Math.cos(deg2rad(lat1)) * Math.cos(deg2rad(lat2)) *
Math.sin(dLon/2) * Math.sin(dLon/2)
;
var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
var d = R * c *1000; // Distance in m
return d;
}
function deg2rad(deg) {
return deg * (Math.PI/180)
}
Finding POIs - By Venue (/poi/get-all-ids)
Use the "getAllPOIs" function as shown in the All POIs sample. Note that the SDK returns the full POI objects, unlike the REST API which only returned the POI IDs which then had to be further queried to obtain details.
Getting POI Data - Multiple POIs (/poi/by-id)
There is no direct mapping for this function. However, getting all All POIs and caching the results provides an effective replacement for this function.
Getting POI Data - Single POI (/poi/by-id)
Use the "getPOIDetails" function as shown in the Single POI sample.
Getting POI Images (/poi/)
Use the "getPOIDetails" function as shown in the Single POI sample to get all poi details including full urls to all image resources.
Resizing/Cropping a POI Image (/x/poi/)
This function is not supported in the SDK. Only full image links are supplied. Any resizing needs to be done by your app.
Route Info (time & distance) - Using Coordinates (/navigate/time-to)
Use the "getDirections" function as shown in the Request Directions Data sample.
Route Info (time & distance) - Using POI ids (/navigate/time-to)
Use the "getDirections" function as shown in the Request Directions Data sample.
Search - General & Category (/search/by-query-string)
Use the "search" function as shown in the General Searches sample. Note that category searches are not supported at this time, but simply omitting the "category:" prefix, will produce the same results in most cases.
Venue Categories (/poi/get-categories)
There is no direct mapping for this function. However, by obtaining a list of All POIs, it is simply a matter of creating a set of the categories returned for each POI, as shown in the code snippet below:
window.map = m;
let categories = new Set();
m.getAllPOIs().then(pois => {
for (const [poiID, poi] of Object.entries(pois)) {
categories.add(poi.category);
}
console.log("Venue categories:", categories);
});
Venue Keywords (/poi/get-keywords)
There is no direct mapping for this function. However, by obtaining a list of All POIs, it is simply a matter of creating a set of the keywords returned for each POI, as shown in the code snippet below:
window.map = m;
let venueTags = new Set();
m.getAllPOIs().then(pois => {
for (const [poiID, poi] of Object.entries(pois)) {
var poiTags = []
for (var keyword of poi.keywords) {
poiTags.push(keyword.name);
}
poiTags.forEach(venueTags.add, venueTags)
}
console.log("Venue tags:", venueTags);
});
Venue Version (/version)
Use the "getVenueData" function as shown in the Getting Venue Data sample. The map version can be obtained by inspecting the "assetVersion" property of appropriate object returned in the "venueList" property.
Updated over 3 years ago