Amazon Location Services - searchPlaceIndexForSuggestions is not a function

470 Views Asked by At

I'm using Amazon Location Services for a mapping project that I'm working on and I want to implement autocomplete using searchPlaceIndexForSuggestions as outlined at https://docs.aws.amazon.com/location/latest/developerguide/search-place-index-autocomplete.html and documented at https://docs.aws.amazon.com/location-places/latest/APIReference/API_SearchPlaceIndexForSuggestions.html

I'm able to call location.searchPlaceIndexForText and location.searchPlaceIndexForPosition just fine and get the expected responses, but when I call location.searchPlaceIndexForSuggestions with relevant parameters I get Uncaught TypeError: location.searchPlaceIndexForSuggestions is not a function.

My declaration for location is

const location = new AWS.Location({credentials, region: AWS.config.region});

The relevant IAM role has the following in its policy:

"Action": [
                "geo:GetMapGlyphs",
                "geo:GetMapSprites",
                "geo:GetMapStyleDescriptor",
                "geo:SearchPlaceIndex*",
                "geo:GetMapTile"
            ],

I'm not sure if I'm missing something in the policy, calling the function incorrectly, declaring location incorrectly, or what. Any ideas or assistance would be appreciated :)

1

There are 1 best solutions below

0
On

Your IAM policy seems fine. There are a couple of things I'd suggest:

  • Take a look at a blog I wrote or a video I published on how to add a location search with autocomplete to your web app using AWS Amplify (Amplify Geo).
  • Take a look at the following code snippet, which uses the AWS SDK V3 Location Client
import {
  LocationClient,
  SearchPlaceIndexForSuggestionsCommand
} from '@aws-sdk/client-location';

const client = new LocationClient({
    credentials: YOUR_AWS_CREDENTIALS,
    region: YOUR_AWS_REGION
  });

const command = new SearchPlaceIndexForSuggestionsCommand({ Text: YOUR_SEARCH_TERM, IndexName: YOUR_PLACE_INDEX_NAME });
const response = await client.send(command)
console.log(response);

Hope this helps.