Autosuggest
Autosuggest endpoint of HERE Geocoding & Search API improves the user’s search experience by allowing submittal of free-form, incomplete and misspelled addresses or place names to the endpoint.
Example
import os
from here_location_services import LS
from here_map_widget import Map, MarkerCluster, ObjectLayer
LS_API_KEY = os.environ.get("LS_API_KEY") # Get API KEY from environment.
ls = LS(api_key=LS_API_KEY)
autosuggest_response = ls.autosuggest(
query="bar",
limit=5,
at=["-13.163068,-72.545128"],
terms_limit=3,
)
results = []
for item in autosuggest_response.items:
if item["resultType"] == "place":
results.append(
dict(
lat=item["position"]["lat"],
lng=item["position"]["lng"],
data=item["title"],
)
)
provider = MarkerCluster(data_points=results, show_bubble=True)
layer = ObjectLayer(provider=provider)
m = Map(
api_key=LS_API_KEY,
center=[-13.16, -72.52],
zoom=14,
)
m.add_layer(layer)
m
Attributes
Attribute |
Type |
Doc |
---|---|---|
query |
string |
A string for free-text query. Example: res, rest |
at |
list |
optional Specify the center of the search context expressed as list of coordinates. One of at, search_in_circle or search_in_bbox is required. Parameters “at”, “search_in_circle” and “search_in_bbox” are mutually exclusive. Only one of them is allowed. |
search_in_circle |
optional Search within a circular geographic area provided as latitude, longitude, and radius (in meters) |
|
search_in_bbox |
tuple |
optional Search within a rectangular bounding box geographic area provided as tuple of west longitude, south latitude, east longitude, north latitude |
in_country |
list |
optional Search within a specific or multiple countries provided as comma-separated ISO 3166-1 alpha-3 country codes. The country codes are to be provided in all uppercase. Must be accompanied by exactly one of at, search_in_circle or search_in_bbox. |
limit |
int |
optional An integer specifiying maximum number of results to be returned. |
terms_limit |
int |
optional An integer specifiying maximum number of Query Terms Suggestions to be returned. |
lang |
list |
optional List of strings to select the language to be used for result rendering from a list of BCP 47 compliant language codes. |
political_view |
string |
optional Toggle the political view by passing a string from |
show |
list |
optional Select additional fields from |