|
1 | | -<!DOCTYPE html> |
| 1 | +<!DOCTYPE html> |
2 | 2 | <html lang="en"> |
3 | 3 | <head> |
4 | 4 | <title>Fill Address Form with Autocomplete - Azure Maps Web SDK Samples</title> |
|
9 | 9 | <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" /> |
10 | 10 | <meta name="description" content="This sample shows how to use the Azure Maps Search service with JQuery UI's autocomplete widget which provides address suggestions as the user types and which populates a form with the selected suggestion." /> |
11 | 11 | <meta name="keywords" content="Microsoft maps, map, gis, API, SDK, search, geocoding, geocode, autocomplete, autosuggest, jquery" /> |
12 | | - <meta name="author" content="Microsoft Azure Maps" /><meta name="version" content="2.0" /> |
| 12 | + <meta name="author" content="Microsoft Azure Maps" /><meta name="version" content="1.0" /> |
13 | 13 | <meta name="screenshot" content="screenshot.jpg" /> |
14 | 14 |
|
15 | 15 | <!-- Load JQuery UI --> |
|
28 | 28 |
|
29 | 29 | var token; |
30 | 30 |
|
31 | | - var addressGeocodeServiceUrlTemplate = 'https://atlas.microsoft.com/geocode:autocomplete?api-version=2025-06-01-preview&query={query}&coordinates={coordinates}&language={language}&countrySet={countrySet}'; |
| 31 | + var addressGeocodeServiceUrlTemplate = 'https://atlas.microsoft.com/geocode:autocomplete?api-version=2025-06-01-preview&query={query}&coordinates={coordinates}&language={language}&resultTypeGroups={resultTypeGroups}&resultTypes={resultTypes}&countryRegion={countryRegion}&top={top}'; |
32 | 32 |
|
33 | 33 | async function PageLoaded() { |
34 | 34 | //Retrieve a SAS token if there isn't one currently available. |
|
45 | 45 | var requestUrl = addressGeocodeServiceUrlTemplate.replace('{query}', encodeURIComponent(request.term)) |
46 | 46 | .replace('{coordinates}', '-95.712891,37.09024') // Default set to US center coordinates |
47 | 47 | .replace('{language}', 'en-US') |
48 | | - .replace('{countrySet}', 'US'); //A comma-separated string of country codes to limit the suggestions to. |
| 48 | + .replace('{resultTypeGroups}', 'Address') |
| 49 | + .replace('{resultTypes}', 'Address') |
| 50 | + .replace('{countryRegion}', 'US') |
| 51 | + .replace('{top}', '10'); // Limit to top 10 results |
49 | 52 |
|
50 | 53 | //Process the request. |
51 | 54 | fetch(requestUrl, { |
|
57 | 60 | 'Accept-Language': 'en-US' |
58 | 61 | } |
59 | 62 | }).then(r => r.json()).then(data => { |
60 | | - // New API returns features array instead of results |
61 | | - // Filter for Address type items only |
62 | | - var results = data.features ? data.features.filter(item => |
63 | | - item.properties && item.properties.typeGroup === "Address" |
64 | | - ) : []; |
| 63 | + // API already filters for Address type items with resultTypeGroups and resultTypes parameters |
| 64 | + var results = data.features || []; |
65 | 65 | response(results); |
66 | 66 | }); |
67 | 67 | }, |
|
168 | 168 | This sample shows how to use the Azure Maps Search service with <a href="https://jqueryui.com/autocomplete/">JQuery UI's autocomplete widget</a> which provides address suggestions as the user types and which populates a form with the selected suggestion. |
169 | 169 | </fieldset> |
170 | 170 | </body> |
171 | | - |
172 | 171 | </html> |
0 commit comments