简体   繁体   English

如何在 Bing 地图 SDK 中使用自动提示进行搜索?

[英]How to make a search with autosuggest in the Bing Maps SDK?

I am trying to use the Bing Maps SDK to display a map in which I show a SearchView .我正在尝试使用 Bing Maps SDK 来显示 map ,其中我显示了SearchView In this SearchView I want to search for locations and when I click on a suggested location, put a marker on the map at that location.在此SearchView中,我想搜索位置,当我单击建议的位置时,在该位置的 map 上放置一个标记。

I have previously used the HERE SDK which has a documentation to do this but on Android I can't find any documentation about this Bing Maps SDK.我以前使用过 HERE SDK,它有一个文档可以执行此操作,但在 Android 上我找不到任何关于此 Bing 地图 SDK 的文档。

What I want to achieve is this in Android: https://www.bing.com/api/maps/sdk/mapcontrol/isdk/autosuggestui#TS我想在 Android 中实现这一点: https://www.bing.com/api/maps/sdk/mapcontrol/isdk/autosuggestui#TS

Documentation on Bing Maps autosuggest service can be found here: https://docs.microsoft.com/en-us/bingmaps/rest-services/autosuggest可以在此处找到有关 Bing 地图自动建议服务的文档: https://docs.microsoft.com/en-us/bingmaps/rest-services/autosuggest

You can use this with Androids AutoCompleteTextView to create a suggestion UI.您可以将它与 Android 的AutoCompleteTextView一起使用来创建建议 UI。 You will retrieve the suggestions asynchronously from the above service.您将从上述服务中异步检索建议。 Here are a few good samples:以下是一些很好的示例:

https://www.truiton.com/2018/06/android-autocompletetextview-suggestions-from-webservice-call/ https://www.truiton.com/2018/06/android-autocompletetextview-suggestions-from-webservice-call/

How to implement autocompletetextview in Android Studio with an API call? 如何通过 API 调用在 Android Studio 中实现 autocompletetextview?

This service does not return coordinates.此服务不返回坐标。 This is done so that it isn't used as a replacement for the geocoding service and thus allows them to make this a lower cost service.这样做是为了不将其用作地理编码服务的替代品,从而使他们能够使其成为成本较低的服务。 When a suggestion is selected by the user, you will need to make a single call to a geocoder to get the coordinates of the formattedAddress , then you can use that to display a marker on the map.当用户选择一个建议时,您需要对地理编码器进行一次调用以获取formattedAddress的坐标,然后您可以使用它在 map 上显示一个标记。 I recommend setting the result limit to 1 since you only want to top result.我建议将结果限制设置为 1,因为您只想获得最高结果。

In summary;总之;

  1. Use addTextChangedListener event of AutoCompleteTextView to retrieve suggestions from the autosuggest service.使用 AutoCompleteTextView 的 addTextChangedListener 事件从自动建议服务中检索建议。
  2. Use setOnItemClickListener event of AutoCompleteTextView to retrieve the selection from the user, and pass the formattedAddress value into the geocoding service.使用 AutoCompleteTextView 的 setOnItemClickListener 事件来检索用户的选择,并将formattedAddress值传递给地理编码服务。
  3. Use the coordinates from the geocoder response to create a marker and add to the map.使用地理编码器响应中的坐标创建标记并添加到 map。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM