@azure/cognitiveservices-localsearch
    TypeScript icon, indicating that this package has built-in type declarations

    2.0.1 • Public • Published

    An isomorphic javascript sdk for - LocalSearchClient

    This package contains an isomorphic SDK for LocalSearchClient.

    Currently supported environments

    • Node.js version 6.x.x or higher
    • Browser JavaScript

    How to Install

    npm install @azure/cognitiveservices-localsearch

    How to use

    nodejs - Authentication, client creation and search local as an example written in TypeScript.

    Install @azure/ms-rest-azure-js
    npm install @azure/ms-rest-azure-js
    Sample code

    The following sample performs an local business search with the query 'Coffee 98052'. To know more, refer to the Azure Documentation on Bing Local Search

    const { LocalSearchClient } = require("@azure/cognitiveservices-localsearch");
    const { CognitiveServicesCredentials } = require("@azure/ms-rest-azure-js");
     
    async function main() {
      const localSearchKey = process.env["localSearchKey"] || "<localSearchKey>";
      const cognitiveServiceCredentials = new CognitiveServicesCredentials(
        localSearchKey
      );
      const client = new LocalSearchClient(cognitiveServiceCredentials, {
        baseUri: "https://api.cognitive.microsoft.com/"
      });
     
      client.local
        .search("Coffee 98052")
        .then(result => {
          console.log("The result is: ");
          result.places.value.forEach(place => {
            console.log(place);
          });
        })
        .catch(err => {
          console.log("An error occurred:");
          console.error(err);
        });
    }
     
    main();
     

    browser - Authentication, client creation and search local as an example written in JavaScript.

    Sample code
    • index.html
    <!DOCTYPE html>
    <html lang="en">
      <head>
        <title>@azure/cognitiveservices-localsearch sample</title>
        <script src="node_modules/@azure/ms-rest-js/dist/msRest.browser.js"></script> 
        <script src="node_modules/@azure/cognitiveservices-localsearch/dist/cognitiveservices-localsearch.js"></script> 
        <script type="text/javascript">
          const localsearchKey = "<YOUR_LOCAL_SEARCH_KEY>";
          const cognitiveServiceCredentials = new msRest.ApiKeyCredentials({
            inHeader: {
              "Ocp-Apim-Subscription-Key": localsearchKey
            }
          });
          const client = new Azure.CognitiveservicesLocalsearch.LocalSearchClient(
            cognitiveServiceCredentials,
            {
              baseUri: "https://api.cognitive.microsoft.com/"
            }
          );
     
          client.local
            .search("Coffee 98052")
            .then(result => {
              console.log("The result is: ");
              result.places.value.forEach(place => {
                console.log(place);
              });
            })
            .catch(err => {
              console.log("An error occurred:");
              console.error(err);
            });
        </script> 
      </head>
      <body></body>
    </html>
     

    Related projects

    Impressions

    Install

    npm i @azure/cognitiveservices-localsearch

    DownloadsWeekly Downloads

    47

    Version

    2.0.1

    License

    MIT

    Unpacked Size

    470 kB

    Total Files

    49

    Last publish

    Collaborators

    • amarzavery
    • azure-sdk
    • billytrend
    • sergeyshandar
    • veronicagg
    • vladbarosan