NeighborhoodMatch displays a list of similar neighborhoods.
First, install the entry script with npm
, yarn
, or pnpm
:
npm i --save @local-logic/sdks-js
yarn add @local-logic/sdks-js
pnpm add @local-logic/sdks-js
The script is also available in umd
and es
format from the Local Logic CDN:
https://sdk.locallogic.co/sdks-js/<VERSION>/index.<FORMAT>.js
<VERSION>
is the latest script version number (which you can find on npm), and <FORMAT>
is either umd
or es
.
<scriptasyncsrc="https://sdk.locallogic.co/sdks-js/1.20.9/index.umd.js"onload="myInitLocalNeighborhoodMatchFunc()"></script>
LLSDKsJS
instanceImport LLSDKsJS
and create a new localLogicSDK
instance. If you installed LLSDKsJS
using a script tag, you must access it from the window
object.
import LLSDKsJS from "@local-logic/sdks-js";const localLogicSDK = LLSDKsJS(// Your API key or token<API_KEY>);
You can authenticate your SDK using an API key or OAuth token. The method you choose depends on your environment; if your page is using server-side rendering (SSR), the OAuth token may be preferrable. If you have a single-page application (SPA), you will likely want to use the API key since the CLIENT_SECRET
needed to generate the OAuth token should never be exposed in a client-side environment.
If you authenticate using the token you need to prefix it with Bearer
.
Next, create an instance of the NeighborhoodMatch SDK. You must define a container element for it to render into.
Example
// Define a container elementconst container = document.createElement("div");container.style.cssText = `height: 100%;width: 100vw;display: flex;`;const neighborhoodLocation = {lat: 37.8,lng: -122.4,};document.body.appendChild(container);localLogicSDK.create("local-neighborhood-match", container, {...neighborhoodLocation,});
The SDKs are designed to work with React and other declarative frameworks.
Example
import { useRef, useEffect } from "react";import LLSDKsJS from "@local-logic/sdks-js";const localLogicSDK = LLSDKsJS(<API_KEY>);function LocalNeihborhoodMatch() {const containerRef = useRef(null);useEffect(() => {if (!containerRef.current) {return;}const myLocation = {lat: 45.5282164,lng: -73.5978527,};const neighborhoodMatch = localLogicSDK.create("local-neighborhood-match",containerRef.current, {...myLocation,});// It is important to destroy the instance when the component is unmounted.return () => {neighborhoodMatch.destroy();}}, []);return (<divref={containerRef}style={{height: "100%",width: "100vw",}}/>);}export default LocalNeihborhoodMatch;
Example
<!DOCTYPE html><html><head><title>NeighborhoodWrap Page Javascript Example</title><meta charset="UTF-8" /></head><body><scriptasyncsrc="https://sdk.locallogic.co/sdks-js/1.20.9/index.umd.js"onload="neighborhoodMatch()"></script><style>#widgetMap {height: 100%;width: 100%;}</style><div id="neighborhoodMatchContainer"></div><script>function neighborhoodMatch() {(async () => {// Your API key or tokenconst ll = LLSDKsJS("<API_KEY>", {locale: "en", // Change to either english or french});const container = document.createElement("div");container.setAttribute("id", "LocalNeihborhoodMatch");// Set the styles of the container// The widget needs to have an adaptable height because it expands to fit the contentcontainer.style.cssText = `height: 100%;width: 100%;display: flex;`;// This is the div that will contain the widgetdocument.querySelector("#neighborhoodMatchContainer").appendChild(container);// Set the lat and lng of the locationconst LAT = 45.528126;const LNG = -73.598104;const localMatch = ll.create("local-neighborhood-match", container, {lat: LAT,lng: LNG,});})();}</script></body></html>
For more information on the different functions available with the SDK, please view our NPM packages documentation.
.update()
The update
method is used to update the widget with new values. This can be useful when, for example, you want to change the widget location.
neighborhoodMatch.update({lat: 43.686941,lng: -79.463814,});
The SDKs are configured with to support these browsers.
The SDKs are designed to receive most new changes (non-breaking features and bug fixes) without the need for a developer to manually update the script.
Local Logic SDKs JS comes packaged with TypeScript declarations.
A: You can change the language by specifying locale
in the LLSDKsJS
options. The supported options are "en"
and "fr"
.
const ll = LocalLogicSDK(// Your API key or token<API_KEY>,{locale: "fr",});