Have you ever wondered how you could search for a specific address in a map and obtain its coordinates?
In this case, GeocodeQuery is the way to go! Let’s start 🙂
First of all, you need to declare a String containing the address you want to look for:
Then, declare a boolean that will be set to true when the route is being searched, otherwise false:
private bool _isRouteSearch = false;
Now it’s time to write the rest of the code (don’t worry, I’ll explain right after what it currently does):
MyGeocodeQuery = new GeocodeQuery(); MyGeocodeQuery.SearchTerm = searchTerm; MyGeocodeQuery.GeoCoordinate = MyCoordinate == null ? new GeoCoordinate(0, 0) : MyCoordinate; MyGeocodeQuery.QueryCompleted += GeocodeQuery_QueryCompleted; MyGeocodeQuery.QueryAsync();
The code itself looks quite straightforward. The QueryAsync() is launched after the SearchTerm has been set, together with the function to launch when the Query gets completed (possibly a group of markers marking the locations searched) and the “start coordinates” of the query have been set with the phone current location.
The result of the GeocodeQuery is a list of MapLocations representing the hits matching the SearchTerm of the query. Each MapLocation has a GeoCoordinate for positioning the location on the map, as well as detailed LocationInformation with name, description and MapAddress of the location. The event handler GeocodeQuery_QueryCompleted is called both when searching the map for a keyword and when searching for a route. The route specific part is explained later on. Here the search results are stored to be later used for drawing map markers.