Skip to content

Instantly share code, notes, and snippets.

@axcellence
Last active April 24, 2023 09:07
Show Gist options
  • Save axcellence/4152302da4c28ef4826629d476b3e1af to your computer and use it in GitHub Desktop.
Save axcellence/4152302da4c28ef4826629d476b3e1af to your computer and use it in GitHub Desktop.
Woosmap MultiSearch API implementation comparison
// Brew Details call
const getSearchDetails = async suggestion => {
const details = await autocompleteService.detailsMulti({
id: suggestion.id,
api: suggestion.api,
})
return details
}
// Brew MultiSearch config
const autocompleteService = window.woosmap.multisearch({
apiOrder: ["localities", "store", "address", "places"],
debounceTime: 100,
store: {
key: conf.woosmapLoadOptions.publicKey,
fallbackBreakpoint: 0.5,
},
localities: {
key: conf.woosmapLoadOptions.publicKey,
fallbackBreakpoint: 0.4,
params: {
components: {
country: ["GB"],
language: "en",
types: ["locality", "country", "postal_code"],
},
},
},
address: {
key: conf.woosmapLoadOptions.publicKey,
fallbackBreakpoint: 0.5,
minInputLength: 5,
params: {
components: { country: ["GBR"] },
language: "en",
},
},
places: {
key: conf.woosmapLoadOptions.publicKey,
fallbackBreakpoint: 1,
minInputLength: 10,
},
});
// Woosmap Details call
// source: https://codesandbox.io/s/multisearch-demo-fallbackbreakpointfalse-43rz9?from-embed=&file=/src/index.js:2578-2878
try {
const result = await multisearchInstance.detailsMulti({ id, api });
showMarker(result);
document.getElementById("autocomplete").value =
result.name || result.formatted_address;
console.log("details", result);
} catch (error) {
console.log(error);
}
// Woosmap MultiSearch usage
// source: https://codesandbox.io/s/multisearch-demo-fallbackbreakpointfalse-43rz9?from-embed=&file=/src/multisearch-config.js
const multisearch = window.woosmap.multisearch({
apiOrder: ["store", "localities", "address", "places"],
debounceTime: 100,
localities: {
key: "woos-03ae8b61-46a4-3a8c-aa26-7c970087d5ba",
fallbackBreakpoint: 0.4,
params: {
components: {
country: ["gb"]
},
language: "gb",
types: []
}
},
address: {
key: "woos-03ae8b61-46a4-3a8c-aa26-7c970087d5ba",
fallbackBreakpoint: 0.5,
minInputLength: 5,
params: {
components: {
country: ["gb"]
},
language: "gb"
}
},
store: {
key: "woos-03ae8b61-46a4-3a8c-aa26-7c970087d5ba",
fallbackBreakpoint: false,
params: {
query: "type:bose_store"
}
},
places: {
key: "AIzaSyAAFBEYl6VnHSyllckphcRWzJlomsoXosA",
fallbackBreakpoint: 1,
minInputLength: 10,
params: {
components: {
country: ["gb"]
}
}
}
});
export default multisearch;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment