Search Location
The RadMap control allows the user to implement search functionality, that will let the user search for a specific place on the map. The search is performed through an IBingRestSearchLocationProvider interface, which communicates with the respective map provider's services. The BingRestMapProvider implements this interface. In the following sections of this article we will demonstrate how you can implement this functionality.
The RadMap search functionality wraps the Location API of the Bing Rest Map services.
Find a place by given Location or Query
In the following examples, we will demonstrate how to find a specific location by given address or location. To do it you can create an instance of the BingRestSearchLocationRequest object which the SearchLocationAsync() method of the BingRestMapProvider uses as a parameter and set its Query property. Then you can subscribe to the SearchLocationCompleted and SearchLocationError events of the BingRestMapProvider. The SearchLocationError event is the place for handling any kind of errors that occur during the search operation. You can take a look at the following steps:
-
Set the ApplicationId property of the BingRestMapProvider. This property represents a key, which allows you to use the Bing Rest Maps services.
Without supplying a valid key you won't be able to visualize the map inside the RadMap control. In order to learn how to obtain one, please read Accessing the Control Using a Bing Maps.
Create instance of the BingRestSearchLocationRequest object
- Handle SearchLocationCompleted and SearchLocationError events of the BingRestMapProvider
- Call SearchLocationAsync() method of the BingRestMapProvider and provide the request as a parameter
The SearchLocationCompleted returns BingRestSearchLocationCompletedEventArgs argument which contains array of Telerik.Windows.Controls.DataVisualization.Map.BingRest.Location objects. This is a complex DataContract object given from the Bing REST services and contains lots of data – address, name, geocode points, district, maneuver type etc. For better overview follow Search sample project.
-
Find a place by Location In this example we will get the location on the MapMouseClick event of the RadMap.
Example 1: Defining BingRestMapProvider in XAML
Example 2: Get location by mouse click
-
Find a place by Address/String Query
The approach here is almost the same as the one explained above. Here we are setting a string address to the Query property of the BingRestSearchLocationRequest object.
Example 3: Defining BingRestMapProvider in XAML
Example 3: Get a location by specific address
Structured / Unstructured URL
The Microsoft Bing Maps REST Service provides two URL templates which you can use to get latitude and longitude coordinates for a location by a given query. To learn more about these templates, please refer to the Find a Location by Address) MSDN article.
With the R1 2018 SP2 version of our controls, you can now change the type of URL which the BingRestMapProvider's search mechanism uses in its code. By default, the BingRestSearchLocationRequest uses the structured URL template. To force the search functionality to use an unstructured URL template, you can set the UseUnstructuredQuery property of the BingRestSearchLocationRequest to True.
Setting one of these URLs depends on how you have structured your query. To search for a location you can type it in structured form, for example, '1 Microsoft way, Redmond WA 98052'. In such a scenario you can use a Structured URL. On the other hand, if you type an unstructured address (or free form query) you should choose the unstructured Bing URL to get better results from the service.